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

fix(Toolbar): close menu when it looses focus #1688

Merged
merged 9 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
7 changes: 7 additions & 0 deletions packages/react/src/components/Toolbar/ToolbarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class ToolbarItem extends UIComponent<WithAsProp<ToolbarItemProps>, ToolbarItemS
{submenu}
</>
),
onBlur: this.handleWrapperBlur,
}),
})
}
Expand All @@ -268,6 +269,12 @@ class ToolbarItem extends UIComponent<WithAsProp<ToolbarItemProps>, ToolbarItemS
return <Ref innerRef={this.itemRef}>{renderedItem}</Ref>
}

handleWrapperBlur = e => {
if (this.props.menu && !e.currentTarget.contains(e.relatedTarget)) {
this.trySetMenuOpen(false, e)
}
}

handleBlur = (e: React.SyntheticEvent) => {
this.setState({ isFromKeyboard: false })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ const toolbarItemBehavior: Accessibility<ToolbarItemBehaviorProps> = props => {
behaviorData.keyActions.wrapper = {
...behaviorData.keyActions.wrapper,
closeMenuAndFocusTrigger: {
keyCombinations: props.menu && props.menuOpen ? [{ keyCode: keyboardKey.Escape }] : null,
keyCombinations:
props.menu && props.menuOpen
? [{ keyCode: keyboardKey.Escape }, { keyCode: keyboardKey.Tab, shiftKey: true }]
: null,
},
doNotNavigateNextToolbarItem: {
keyCombinations:
Expand Down