diff --git a/app/javascript/mastodon/features/compose/components/federation_dropdown.js b/app/javascript/mastodon/features/compose/components/federation_dropdown.js index 99a3c0164..4216530e2 100644 --- a/app/javascript/mastodon/features/compose/components/federation_dropdown.js +++ b/app/javascript/mastodon/features/compose/components/federation_dropdown.js @@ -18,6 +18,8 @@ const messages = defineMessages({ const listenerOptions = supportsPassiveEvents ? { passive: true } : false; +const getValue = element => element.dataset.index === 'true'; + class FederationDropdownMenu extends React.PureComponent { static propTypes = { @@ -40,7 +42,7 @@ class FederationDropdownMenu extends React.PureComponent { handleKeyDown = e => { const { items } = this.props; - const value = Boolean(e.currentTarget.getAttribute('data-index')); + const value = getValue(e.currentTarget); const index = items.findIndex(item => { return (item.value === value); }); @@ -57,40 +59,38 @@ class FederationDropdownMenu extends React.PureComponent { element = this.node.childNodes[index + 1]; if (element) { element.focus(); - this.props.onChange(Boolean(element.getAttribute('data-index'))); + this.props.onChange(getValue(element)); } break; case 'ArrowUp': element = this.node.childNodes[index - 1]; if (element) { element.focus(); - this.props.onChange(Boolean(element.getAttribute('data-index'))); + this.props.onChange(getValue(element)); } break; case 'Home': element = this.node.firstChild; if (element) { element.focus(); - this.props.onChange(Boolean(element.getAttribute('data-index'))); + this.props.onChange(getValue(element)); } break; case 'End': element = this.node.lastChild; if (element) { element.focus(); - this.props.onChange(Boolean(element.getAttribute('data-index'))); + this.props.onChange(getValue(element)); } break; } } handleClick = e => { - const value = Boolean(e.currentTarget.getAttribute('data-index')); - e.preventDefault(); this.props.onClose(); - this.props.onChange(value); + this.props.onChange(getValue(e.currentTarget)); } componentDidMount () { @@ -125,7 +125,7 @@ class FederationDropdownMenu extends React.PureComponent { // react-overlays
{items.map(item => ( -
+