Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Remove `color` prop from `Dialog` typings @layershifter ([#1702](https://github.com/stardust-ui/react/pull/1702))
- `Loader` uses `Text` component for `label` slot instead of `Box` @layershifter ([#1701](https://github.com/stardust-ui/react/pull/1701))
- Fix test cut off in `Button` component @layershifter ([#1716](https://github.com/stardust-ui/react/pull/1716))
- Close `Toolbar`'s menu when it looses focus @sophieH29 ([#1688](https://github.com/stardust-ui/react/pull/1688))

### Documentation
- Make sidebar categories collapsible @lucivpav ([#1611](https://github.com/stardust-ui/react/pull/1611))
Expand Down
14 changes: 10 additions & 4 deletions packages/react/src/components/Toolbar/ToolbarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,14 @@ class ToolbarItem extends UIComponent<WithAsProp<ToolbarItemProps>, ToolbarItemS
this.handleClick(event)
},
closeMenuAndFocusTrigger: event => {
if (!this.props.menuOpen) {
return
}

this.trySetMenuOpen(false, event)
if (this.itemRef) {
this.itemRef.current.focus()
}
},
closeMenu: () => {
this.trySetMenuOpen(false, event)
},
doNotNavigateNextToolbarItem: event => {
event.stopPropagation()
},
Expand Down Expand Up @@ -253,6 +252,7 @@ class ToolbarItem extends UIComponent<WithAsProp<ToolbarItemProps>, ToolbarItemS
{submenu}
</>
),
onBlur: this.handleWrapperBlur,
}),
})
}
Expand All @@ -268,6 +268,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 @@ -24,6 +24,10 @@ const toolbarItemBehavior: Accessibility<ToolbarItemBehaviorProps> = props => {
closeMenuAndFocusTrigger: {
keyCombinations: props.menu && props.menuOpen ? [{ keyCode: keyboardKey.Escape }] : null,
},
closeMenu: {
keyCombinations:
props.menu && props.menuOpen ? [{ keyCode: keyboardKey.Tab, shiftKey: true }] : null,
},
doNotNavigateNextToolbarItem: {
keyCombinations:
props.menu && props.menuOpen
Expand Down