Skip to content

Commit

Permalink
add option to auto focus specific menu item (#109)
Browse files Browse the repository at this point in the history
* add option to auto focus specific menu item

* bump version
  • Loading branch information
amirbardugo authored Apr 21, 2021
1 parent 5510da6 commit 6d81ae4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monday-ui-react-core",
"version": "0.3.5",
"version": "0.3.6",
"description": "Official monday.com UI resources for application development in React.js",
"main": "dist/main.js",
"scripts": {
Expand Down
11 changes: 9 additions & 2 deletions src/components/Menu/Menu/Menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const Menu = forwardRef(
onClose,
focusOnMount,
focusItemIndex,
focusItemIndexOnMount,
isSubMenu,
useDocumentEventListeners
},
Expand All @@ -34,6 +35,10 @@ const Menu = forwardRef(
const ref = useRef(null);
const [activeItemIndex, setActiveItemIndex] = useState(focusItemIndex);

useEffect(() => {
if (focusItemIndexOnMount !== -1) setActiveItemIndex(focusItemIndexOnMount);
}, [focusItemIndexOnMount]);

const children = useMemo(() => {
const allChildren = React.Children.toArray(originalChildren);
const menuChildren = allChildren.filter(child => {
Expand Down Expand Up @@ -146,7 +151,8 @@ Menu.defaultProps = {
onClose: undefined,
focusItemIndex: -1,
isSubMenu: false,
useDocumentEventListeners: false
useDocumentEventListeners: false,
focusItemIndexOnMount: -1
};

Menu.propTypes = {
Expand All @@ -161,7 +167,8 @@ Menu.propTypes = {
onClose: PropTypes.func,
focusItemIndex: PropTypes.number,
isSubMenu: PropTypes.bool,
useDocumentEventListeners: PropTypes.bool
useDocumentEventListeners: PropTypes.bool,
focusItemIndexOnMount: PropTypes.number
};

export default Menu;

0 comments on commit 6d81ae4

Please sign in to comment.