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'; ...@@ -7,10 +7,11 @@ import styles from './language-selector.css';
// supported languages to exclude from the menu, but allow as a URL option // supported languages to exclude from the menu, but allow as a URL option
const ignore = []; const ignore = [];
const LanguageSelector = ({currentLocale, label, onChange}) => ( const LanguageSelector = ({componentRef, currentLocale, label, onChange}) => (
<select <select
aria-label={label} aria-label={label}
className={styles.languageSelect} className={styles.languageSelect}
ref={componentRef}
value={currentLocale} value={currentLocale}
onChange={onChange} onChange={onChange}
> >
...@@ -30,6 +31,7 @@ const LanguageSelector = ({currentLocale, label, onChange}) => ( ...@@ -30,6 +31,7 @@ const LanguageSelector = ({currentLocale, label, onChange}) => (
); );
LanguageSelector.propTypes = { LanguageSelector.propTypes = {
componentRef: PropTypes.func,
currentLocale: PropTypes.string, currentLocale: PropTypes.string,
label: PropTypes.string, label: PropTypes.string,
onChange: PropTypes.func onChange: PropTypes.func
......
...@@ -11,10 +11,31 @@ class LanguageSelector extends React.Component { ...@@ -11,10 +11,31 @@ class LanguageSelector extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
bindAll(this, [ bindAll(this, [
'handleChange' 'handleChange',
'handleMouseOut',
'ref'
]); ]);
document.documentElement.lang = props.currentLocale; 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) { handleChange (e) {
const newLocale = e.target.value; const newLocale = e.target.value;
if (this.props.messagesByLocale[newLocale]) { if (this.props.messagesByLocale[newLocale]) {
...@@ -31,6 +52,7 @@ class LanguageSelector extends React.Component { ...@@ -31,6 +52,7 @@ class LanguageSelector extends React.Component {
} = this.props; } = this.props;
return ( return (
<LanguageSelectorComponent <LanguageSelectorComponent
componentRef={this.ref}
onChange={this.handleChange} onChange={this.handleChange}
{...props} {...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