1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-01-23 18:34:02 +02:00

Allow nested MenuWrappers to close on item click

This commit is contained in:
Chen-I Lim 2020-11-10 11:24:07 -08:00
parent 289f8f9d30
commit 6445231737
4 changed files with 8 additions and 3 deletions

View File

@ -11,7 +11,8 @@ type ColorOptionProps = MenuOptionProps & {
}
export default class ColorOption extends React.PureComponent<ColorOptionProps> {
private handleOnClick = (): void => {
private handleOnClick = (e: React.MouseEvent): void => {
e.target.dispatchEvent(new Event('menuItemClicked'))
this.props.onClick(this.props.id)
}

View File

@ -12,7 +12,8 @@ type SwitchOptionProps = MenuOptionProps & {
}
export default class SwitchOption extends React.PureComponent<SwitchOptionProps> {
private handleOnClick = (): void => {
private handleOnClick = (e: React.MouseEvent): void => {
e.target.dispatchEvent(new Event('menuItemClicked'))
this.props.onClick(this.props.id)
}

View File

@ -10,7 +10,8 @@ type TextOptionProps = MenuOptionProps & {
}
export default class TextOption extends React.PureComponent<TextOptionProps> {
private handleOnClick = (): void => {
private handleOnClick = (e: React.MouseEvent): void => {
e.target.dispatchEvent(new Event('menuItemClicked'))
this.props.onClick(this.props.id)
}

View File

@ -32,11 +32,13 @@ export default class MenuWrapper extends React.PureComponent<Props, State> {
}
public componentDidMount() {
document.addEventListener('menuItemClicked', this.close, true)
document.addEventListener('click', this.closeOnBlur, true)
document.addEventListener('keyup', this.keyboardClose, true)
}
public componentWillUnmount() {
document.removeEventListener('menuItemClicked', this.close, true)
document.removeEventListener('click', this.closeOnBlur, true)
document.removeEventListener('keyup', this.keyboardClose, true)
}