Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

fix(Toolbar): ToolbarMenuItem doesn't focus menu trigger element after 'onClick' was executed #2367

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const doList = [
`aria-labelledby` props). Refer to{' '}
{link('toolbar(role)', 'https://www.w3.org/WAI/PF/aria/roles#toolbar')} for details.
</Text>,
'If `Toolbar` contains menu, then focus will need be handled after `onClick` is executed on `menuItem`.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'If Toolbar contains menu, the menu closes after clicking on one of the menu items. To prevent losing focus, move it manually in the onClick handler.

]

const ToolbarBestPractices: React.FunctionComponent<{}> = () => {
Expand Down
4 changes: 0 additions & 4 deletions packages/react/src/components/Toolbar/ToolbarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ class ToolbarItem extends UIComponent<WithAsProp<ToolbarItemProps>> {
}
// TODO: should we pass toolbarMenuItem to the user callback so he can decide if he wants to close the menu?
this.trySetMenuOpen(menuOpen, e)
if (!menuOpen) {
_.invoke(this.itemRef.current, 'focus')
}
},
variables: mergeComponentVariables(variables, predefinedProps.variables),
})
Expand Down Expand Up @@ -322,7 +319,6 @@ class ToolbarItem extends UIComponent<WithAsProp<ToolbarItemProps>> {
if (menu) {
if (doesNodeContainClick(this.menuRef.current, e, this.context.target)) {
this.trySetMenuOpen(false, e)
_.invoke(this.itemRef.current, 'focus')
}
}
}
Expand Down