Skip to content

Commit 1612e9b

Browse files
authored
Merge pull request #285 from sparksuite/polishing-touches
Bump minor version + polishing touches
2 parents 02be492 + 4c2e387 commit 1612e9b

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-accessible-dropdown-menu-hook",
3-
"version": "3.0.0",
3+
"version": "3.1.0",
44
"description": "A simple Hook for creating fully accessible dropdown menus in React",
55
"main": "dist/use-dropdown-menu.js",
66
"types": "dist/use-dropdown-menu.d.ts",

src/use-dropdown-menu.test.tsx

+7-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface Props {
1111

1212
const TestComponent: React.FC<Props> = ({ options }) => {
1313
const [itemCount, setItemCount] = useState(4);
14-
const { buttonProps, itemProps, isOpen, moveFocus, setIsOpen } = useDropdownMenu(itemCount, options);
14+
const { buttonProps, itemProps, isOpen, setIsOpen, moveFocus } = useDropdownMenu(itemCount, options);
1515

1616
const clickHandlers: (() => void)[] = [(): void => console.log('Item one clicked'), (): void => setIsOpen(false)];
1717

@@ -28,7 +28,6 @@ const TestComponent: React.FC<Props> = ({ options }) => {
2828
key={i}
2929
id={`menu-item-${i + 1}`}
3030
onClick={clickHandlers[i]}
31-
onMouseEnter={(): void => moveFocus(i)}
3231
href={i > 1 ? 'https://example.com' : undefined}
3332
>
3433
{i + 1} Item
@@ -46,6 +45,10 @@ const TestComponent: React.FC<Props> = ({ options }) => {
4645
Add Item
4746
</button>
4847

48+
<button data-testid='focus-third-item' onClick={(): void => moveFocus(2)}>
49+
Focus third item
50+
</button>
51+
4952
<span data-testid='is-open-indicator'>{isOpen ? 'true' : 'false'}</span>
5053
</React.Fragment>
5154
);
@@ -542,7 +545,7 @@ it('Moves the focus to the menu item with a label that starts with the correspon
542545
expect(screen.getByText('3 Item')).toHaveFocus();
543546
});
544547

545-
it('Moves the focus to the menu item currently hovered over by mouse', () => {
548+
it('Moves the focus to the provided menu item when `moveFocus` is called', () => {
546549
render(<TestComponent />);
547550

548551
userEvent.tab();
@@ -551,13 +554,7 @@ it('Moves the focus to the menu item currently hovered over by mouse', () => {
551554
skipClick: true,
552555
});
553556

554-
fireEvent(
555-
screen.getByText('3 Item'),
556-
new MouseEvent('mouseover', {
557-
bubbles: true,
558-
cancelable: true,
559-
})
560-
);
557+
userEvent.click(screen.getByTestId('focus-third-item'));
561558

562559
expect(screen.getByText('3 Item')).toHaveFocus();
563560
});

website/docs/design/return-object.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ This Hook returns an object of the following shape:
4545
- **ref:** A React ref applied to each menu item, used to manage focus.
4646
- **isOpen:** A boolean value indicating if the menu is open or closed. The developer should use this value to make the menu visible or not.
4747
- **setIsOpen:** A function useful for allowing the developer to programmatically open/close the menu.
48-
- **moveFocus:** A function that changes internal pointer of currently focused element. This is useful when you want to allow seamless switching between keyboard and mouse use.
48+
- **moveFocus:** A function that moves the browser’s focus to the specified item index.

0 commit comments

Comments
 (0)