Skip to content

Commit

Permalink
escape stop propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
Xindi Xu committed Jul 20, 2020
1 parent b611b9b commit 85d13bd
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/components/skins-dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class SkinsDot extends Skins {
this.handleKeyDown = this.handleKeyDown.bind(this)
this.handleSkinKeyDown = this.handleSkinKeyDown.bind(this)
this.setSkinTonesRef = this.setSkinTonesRef.bind(this)

this.onClose = this.onClose.bind(this)
this.skinTones = null
}

Expand Down Expand Up @@ -47,13 +47,10 @@ export default class SkinsDot extends Skins {
case 'Enter':
case 'Space':
this.handleClick(e)
this.setState({ opened: false }, () => {
this.skinTones.focus()
})
e.stopPropagation()
this.onClose(e)

case 'Escape':
this.setState({ opened: false })
this.onClose(e)

default:
break
Expand All @@ -64,6 +61,12 @@ export default class SkinsDot extends Skins {
this.skinTones = c
}

onClose(e) {
this.setState({ opened: false }, () => {
this.skinTones.focus()
})
e.stopPropagation()
}
render() {
const { skin, i18n } = this.props
const { opened } = this.state
Expand All @@ -81,7 +84,12 @@ export default class SkinsDot extends Skins {
{...(opened ? { role: 'menuitem' } : {})}
>
<span
onClick={this.handleClick}
onClick={(e) => {
if (opened) {
this.handleClick(e)
this.onClose(e)
}
}}
onKeyDown={(e) => this.handleSkinKeyDown(e, skinTone)}
tabIndex={opened ? '0' : '-1'}
role="button"
Expand Down Expand Up @@ -109,7 +117,6 @@ export default class SkinsDot extends Skins {
<div
{...(opened ? { role: 'menubar' } : {})}
tabIndex={'0'}
onFocus={() => console.log('focus')}
onClick={this.handleMenuClick}
onKeyDown={this.handleKeyDown}
ref={this.setSkinTonesRef}
Expand Down

0 comments on commit 85d13bd

Please sign in to comment.