Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding state to track if user is on keyboard to control hover & focus… #652

Merged
merged 2 commits into from Oct 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion assets/scss/components/_dropdown.scss
Expand Up @@ -5,7 +5,8 @@
justify-content: flex-start;
padding: calc(var(--responsive-space) / 2);

&:hover {
&:hover,
&:focus {
background-color: $C_coolGrayLight;
}

Expand Down
8 changes: 8 additions & 0 deletions src/interactive/Dropdown.jsx
Expand Up @@ -56,11 +56,13 @@ type Props = {

type State = {
isActive: boolean,
isKeyPressed: boolean,
};

class Dropdown extends React.PureComponent<Props, State> {
state = {
isActive: this.props.isActive || false,
isKeyPressed: false,
};

static defaultProps = {
Expand Down Expand Up @@ -100,6 +102,7 @@ class Dropdown extends React.PureComponent<Props, State> {
this.closeContent(e);
}, 0);
}
this.setState({ isKeyPressed: true });
};

onBodyClick = (e: SyntheticMouseEvent<*>) => {
Expand All @@ -122,6 +125,8 @@ class Dropdown extends React.PureComponent<Props, State> {
}
};

onMouseLeave = () => this.setState({ isKeyPressed: false });

componentDidMount() {
if (document.body) {
document.body.addEventListener('click', this.onBodyClick);
Expand Down Expand Up @@ -193,6 +198,7 @@ class Dropdown extends React.PureComponent<Props, State> {
<div
className={classNames.dropdown}
onKeyDown={this.onKeyDown}
onMouseLeave={this.onMouseLeave}
{...other}
>
<div
Expand Down Expand Up @@ -268,6 +274,8 @@ class Dropdown extends React.PureComponent<Props, State> {
),
style: {
backgroundColor:
this.state
.isKeyPressed &&
highlightedIndex ===
index &&
C_COOLGRAYLIGHTTRANSP,
Expand Down