Skip to content

Commit fb1f15c

Browse files
corymharperWesCossick
authored andcommitted
Updated README to detail recent changes (#73)
1 parent 2f8606a commit fb1f15c

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import useDropdownMenu from 'react-accessible-dropdown-menu-hook';
2525
Call the Hook, telling it how many items your menu will have.
2626

2727
```tsx
28-
const [buttonProps, itemProps, isOpen] = useDropdownMenu(numberOfItems);
28+
const { buttonProps, itemProps, isOpen, setIsOpen } = useDropdownMenu(numberOfItems);
2929
```
3030

3131
Spread the `buttonProps` onto a button:
@@ -45,6 +45,50 @@ Create the menu with the `role='menu'` property and spread `itemProps[x]` onto e
4545

4646
Done!
4747

48+
## Design
49+
This Hook returns an object of the following shape:
50+
51+
```ts
52+
{
53+
buttonProps: {
54+
onKeyDown: (e: React.KeyboardEvent | React.MouseEvent) => void;
55+
onClick: (e: React.KeyboardEvent | React.MouseEvent) => void;
56+
tabIndex: 0;
57+
ref: React.RefObject<HTMLButtonElement>;
58+
role: 'button';
59+
'aria-haspopup': true;
60+
'aria-expanded': boolean;
61+
};
62+
itemProps: [
63+
{
64+
onKeyDown: (e: React.KeyboardEvent<HTMLAnchorElement>) => void;
65+
tabIndex: -1;
66+
role: 'menuitem';
67+
ref: React.RefObject<HTMLAnchorElement>;
68+
};
69+
...
70+
];
71+
isOpen: boolean;
72+
setIsOpen: (newValue: boolean) => void;
73+
}
74+
```
75+
76+
- **buttonProps:** An object meant to be spread as properties on a `<button />` element.
77+
- **onKeyDown:** A function which manages the behavior of your dropdown menu when a key is pressed while focused on the menu button.
78+
- **onClick:** The same function as `onKeyDown()`, but its behavior differs somewhat for click events.
79+
- **tabIndex:** Sets the tab index property of the `<button />` element.
80+
- **ref:** A React ref applied to the `<button />` element, used to manage focus.
81+
- **role:** A role property in accordance with WAI-ARIA guidelines.
82+
- **aria-haspopup:** An ARIA attribute indicating this button has a related menu element.
83+
- **aria-expanded:** An ARIA attribute indicating whether the menu is currently open.
84+
- **itemProps:** An array of objects meant to be spread as properties on `<a />` elements that serve as menu items in your dropdown.
85+
- **onKeyDown:** A function which manages the behavior of your dropdown menu when a key is pressed while focused on a menu item.
86+
- **tabIndex:** Sets the tab index property to `-1` to prevent the browser's native focusing logic. Focus is managed programatically by this Hook.
87+
- **role:** A role property in accordance with WAI-ARIA guidelines.
88+
- **ref:** A React ref applied to each menu item, used to manage focus.
89+
- **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.
90+
- **setIsOpen:** A function useful for allowing the developer to programmatically open/close the menu.
91+
4892
## Accessibility notes
4993
Our team carefully studied and adhered to [Web Content Accessibility Guidelines 2.1](https://www.w3.org/WAI/standards-guidelines/wcag/) and [WAI-ARIA Authoring Practices 1.1](https://www.w3.org/TR/wai-aria-practices/) when designing this Hook. Here are some facets of accessibility that are handled automatically:
5094

0 commit comments

Comments
 (0)