Skip to content
Snippets Groups Projects
Unverified Commit 9c5417fa authored by chrisgarrity's avatar chrisgarrity Committed by GitHub
Browse files

Merge pull request #3583 from chrisgarrity/issue/3302-language-focus

Blur language select focus when mouse leaves
parents a5aea97f a8e338fa
No related branches found
No related tags found
No related merge requests found
......@@ -7,10 +7,11 @@ import styles from './language-selector.css';
// supported languages to exclude from the menu, but allow as a URL option
const ignore = [];
const LanguageSelector = ({currentLocale, label, onChange}) => (
const LanguageSelector = ({componentRef, currentLocale, label, onChange}) => (
<select
aria-label={label}
className={styles.languageSelect}
ref={componentRef}
value={currentLocale}
onChange={onChange}
>
......@@ -30,6 +31,7 @@ const LanguageSelector = ({currentLocale, label, onChange}) => (
);
LanguageSelector.propTypes = {
componentRef: PropTypes.func,
currentLocale: PropTypes.string,
label: PropTypes.string,
onChange: PropTypes.func
......
......@@ -11,10 +11,31 @@ class LanguageSelector extends React.Component {
constructor (props) {
super(props);
bindAll(this, [
'handleChange'
'handleChange',
'handleMouseOut',
'ref'
]);
document.documentElement.lang = props.currentLocale;
}
componentDidMount () {
this.addListeners();
}
componentWillUnmount () {
this.removeListeners();
}
addListeners () {
this.select.addEventListener('mouseout', this.handleMouseOut);
}
removeListeners () {
this.select.removeEventListener('mouseout', this.handleMouseOut);
}
handleMouseOut () {
this.select.blur();
}
ref (c) {
this.select = c;
}
handleChange (e) {
const newLocale = e.target.value;
if (this.props.messagesByLocale[newLocale]) {
......@@ -31,6 +52,7 @@ class LanguageSelector extends React.Component {
} = this.props;
return (
<LanguageSelectorComponent
componentRef={this.ref}
onChange={this.handleChange}
{...props}
>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment