Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Commit

Permalink
feat(Dropdown): Add Hover functionality (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
jadenlemmon authored and kylealwyn committed Aug 30, 2018
1 parent f433062 commit cf88176
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Dropdown/Dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ const getDropdownMenuStyles = props => `
const DropdownProvider = styled.div`
position: relative;
display: inline-block;
z-index: 10;
`;

const DropdownTrigger = styled.div`
cursor: pointer;
`;

const DropdownMenu = styled.div`
z-index: 10;
position: absolute;
left: 50%;
background: white;
Expand All @@ -96,11 +96,13 @@ export default class Dropdown extends React.Component {
render: PropTypes.func,
autoclose: PropTypes.bool,
position: PropTypes.string,
on: PropTypes.string,
};

static defaultProps = {
autoclose: true,
position: 'bl',
on: 'click',
};

static childContextTypes = {
Expand All @@ -125,13 +127,20 @@ export default class Dropdown extends React.Component {
}

toggle = () => {
if (this.props.on !== 'click') return;

if (this.state.isOpen) {
this.close();
} else {
this.open();
}
};

toggleHover = () => {
if (this.props.on !== 'hover') return;
this.setState({ isOpen: !this.state.isOpen });
};

close = () => {
this.setState(
{
Expand Down Expand Up @@ -176,7 +185,13 @@ export default class Dropdown extends React.Component {
innerRef={ref => {
this.root = ref;
}}>
<DropdownTrigger onClick={this.toggle} aria-haspopup="true" aria-expanded={isOpen}>
<DropdownTrigger
onFocus={this.toggleHover}
onMouseOver={this.toggleHover}
onMouseLeave={this.toggleHover}
onClick={this.toggle}
aria-haspopup="true"
aria-expanded={isOpen}>
{trigger}
</DropdownTrigger>

Expand Down

0 comments on commit cf88176

Please sign in to comment.