Commit a7f8a8d2 by Ari Rizzitano

better focus management

parent 679d701e
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -23,6 +23,8 @@ function Button(props) { ...@@ -23,6 +23,8 @@ function Button(props) {
onClick={props.onClick} onClick={props.onClick}
onKeyDown={props.onKeyDown} onKeyDown={props.onKeyDown}
type={props.type} type={props.type}
ref={props.inputRef}
{...props}
> >
{props.display} {props.display}
</button> </button>
...@@ -33,6 +35,7 @@ Button.propTypes = { ...@@ -33,6 +35,7 @@ Button.propTypes = {
buttonType: PropTypes.string, buttonType: PropTypes.string,
classNames: PropTypes.arrayOf(PropTypes.string), classNames: PropTypes.arrayOf(PropTypes.string),
display: PropTypes.string.isRequired, display: PropTypes.string.isRequired,
inputRef: PropTypes.func,
onBlur: PropTypes.func, onBlur: PropTypes.func,
onClick: PropTypes.func, onClick: PropTypes.func,
onKeyDown: PropTypes.func, onKeyDown: PropTypes.func,
...@@ -42,6 +45,7 @@ Button.propTypes = { ...@@ -42,6 +45,7 @@ Button.propTypes = {
Button.defaultProps = { Button.defaultProps = {
buttonType: undefined, buttonType: undefined,
classNames: [], classNames: [],
inputRef: () => {},
onBlur: () => {}, onBlur: () => {},
onClick: () => {}, onClick: () => {},
onKeyDown: () => {}, onKeyDown: () => {},
......
...@@ -47,6 +47,8 @@ class Dropdown extends React.Component { ...@@ -47,6 +47,8 @@ class Dropdown extends React.Component {
componentDidUpdate() { componentDidUpdate() {
if (this.state.open) { if (this.state.open) {
this.menuItems[this.state.focusIndex].focus(); this.menuItems[this.state.focusIndex].focus();
} else if (this.toggleElem) {
this.toggleElem.focus();
} }
} }
...@@ -86,7 +88,6 @@ class Dropdown extends React.Component { ...@@ -86,7 +88,6 @@ class Dropdown extends React.Component {
this.toggle(); this.toggle();
} else if (this.state.open && Dropdown.isTriggerKey('CLOSE_MENU', e.key)) { } else if (this.state.open && Dropdown.isTriggerKey('CLOSE_MENU', e.key)) {
this.toggle(); this.toggle();
this.toggleElem.focus();
} }
} }
...@@ -138,7 +139,7 @@ class Dropdown extends React.Component { ...@@ -138,7 +139,7 @@ class Dropdown extends React.Component {
dd['dropdown-toggle'], dd['dropdown-toggle'],
]} ]}
type="button" type="button"
ref={(toggleElem) => { this.toggleElem = toggleElem; }} inputRef={(toggleElem) => { this.toggleElem = toggleElem; }}
/> />
<ul <ul
aria-label={this.props.title} aria-label={this.props.title}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment