Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (onSelect) {
onSelect(option.props.value, option);
}
} else if (keyCode === KeyCode.KEY_RETURN && active !== null && MenuUtil.includes(value, active)) {
event.preventDefault();
const option = MenuUtil.findByValue(children, active);
// Handles communicating the case where a regular option is Unselected to screen readers.
if (visuallyHiddenComponent && visuallyHiddenComponent.current) {
visuallyHiddenComponent.current.innerHTML = intl.formatMessage({ id: 'Terra.form.select.unselectedText' }, { text: option.props.display });
}
if (onDeselect) {
onDeselect(option.props.value, option);
}
} else if (keyCode === KeyCode.KEY_HOME) {
event.preventDefault();
this.setState({ active: MenuUtil.findFirst(children) });
} else if (keyCode === KeyCode.KEY_END) {
event.preventDefault();
this.setState({ active: MenuUtil.findLast(children) });
}
}
if (onSelect) {
onSelect(option.props.value, option);
}
} else if (keyCode === KeyCode.KEY_RETURN && active !== null && MenuUtil.includes(value, active)) {
event.preventDefault();
const option = MenuUtil.findByValue(children, active);
// Handles communicating the case where a regular option is Unselected to screen readers.
if (visuallyHiddenComponent && visuallyHiddenComponent.current) {
visuallyHiddenComponent.current.innerHTML = intl.formatMessage({ id: 'Terra.form.select.unselectedText' }, { text: option.props.display });
}
if (onDeselect) {
onDeselect(option.props.value, option);
}
} else if (keyCode === KeyCode.KEY_HOME) {
event.preventDefault();
this.setState({ active: MenuUtil.findFirst(children) });
} else if (keyCode === KeyCode.KEY_END) {
event.preventDefault();
this.setState({ active: MenuUtil.findLast(children) });
}
}
}
// Handles communicating the case where a regular option is selected to screen readers.
/*
Detecting if browser is not Safari before updating aria-live as there is some odd behaivor
with VoiceOver on desktop, that causes the selected option to be read twice when this is
is added to aria-live container.
When we shift focus back to select, VoiceOver automatically reads the display text.
Using aria-hidden on the display does not prevent VO from reading the display text and so it
results in reading the display text followed by reading the aria-live message which is
the display text + 'selected'
*/
if (!SharedUtil.isSafari()) {
this.props.visuallyHiddenComponent.current.innerText = `${option.props.display} ${selectedTxt}`;
}
onSelect(option.props.value, option);
} else if (keyCode === KeyCode.KEY_HOME) {
event.preventDefault();
this.setState({ active: MenuUtil.findFirst(children) });
} else if (keyCode === KeyCode.KEY_END) {
event.preventDefault();
this.setState({ active: MenuUtil.findLast(children) });
}
}
if (!this.pressed) {
this.pressed = true;
this.setState({ active: focused });
}
event.preventDefault();
} else if (keyCode === KeyCode.KEY_DOWN) {
if (!this.pressed) {
this.changeFocusState(Util.findNext(this, this.state.focused));
}
event.preventDefault();
} else if (keyCode === KeyCode.KEY_UP) {
if (!this.pressed) {
this.changeFocusState(Util.findPrevious(this, this.state.focused));
}
event.preventDefault();
} else if (keyCode === KeyCode.KEY_HOME) {
if (!this.pressed) {
this.changeFocusState(0);
}
event.preventDefault();
} else if (keyCode === KeyCode.KEY_END) {
if (!this.pressed) {
this.changeFocusState(Util.getChildArray(this).length - 1);
}
event.preventDefault();
} else if (keyCode === KeyCode.KEY_TAB) {
this.props.requestClose();
event.preventDefault();
} else if (keyCode >= 48 && keyCode <= 90) {
this.searchString = this.searchString.concat(String.fromCharCode(keyCode));
clearTimeout(this.searchTimeout);
this.searchTimeout = setTimeout(this.clearSearch, 500);
/*
Detecting if browser is not Safari before updating aria-live as there is some odd behaivor
with VoiceOver on desktop, that causes the selected option to be read twice when this is
is added to aria-live container.
When we shift focus back to select, VoiceOver automatically reads the display text.
Using aria-hidden on the display does not prevent VO from reading the display text and so it
results in reading the display text followed by reading the aria-live message which is
the display text + 'selected'
*/
if (!SharedUtil.isSafari()) {
this.props.visuallyHiddenComponent.current.innerText = `${option.props.display} ${selectedTxt}`;
}
}
onSelect(option.props.value, option);
} else if (keyCode === KeyCode.KEY_HOME) {
event.preventDefault();
this.setState({ active: MenuUtil.findFirst(children) });
} else if (keyCode === KeyCode.KEY_END) {
event.preventDefault();
this.setState({ active: MenuUtil.findLast(children) });
}
}
/*
Detecting if browser is not Safari before updating aria-live as there is some odd behaivor
with VoiceOver on desktop, that causes the selected option to be read twice when this is
is added to aria-live container.
When we shift focus back to select, VoiceOver automatically reads the display text.
Using aria-hidden on the display does not prevent VO from reading the display text and so it
results in reading the display text followed by reading the aria-live message which is
the display text + 'selected'
*/
if (!SharedUtil.isSafari()) {
visuallyHiddenComponent.current.innerText = `${option.props.display} ${selectedTxt}`;
}
}
onSelect(option.props.value, option);
} else if (keyCode === KeyCode.KEY_HOME) {
event.preventDefault();
this.setState({ active: MenuUtil.findFirst(children) });
} else if (keyCode === KeyCode.KEY_END) {
event.preventDefault();
this.setState({ active: MenuUtil.findLast(children) });
} else if (keyCode >= 48 && keyCode <= 90) {
this.searchString = this.searchString.concat(key);
clearTimeout(this.searchTimeout);
this.searchTimeout = setTimeout(this.clearSearch, 500);
this.setState(prevState => ({ active: MenuUtil.findWithStartString(prevState.children, this.searchString) || active }));
}
}