Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Commit

Permalink
Dropdown Improvements (#820)
Browse files Browse the repository at this point in the history
Included in this change is:
- adding spacing between dropdown menu and the trigger
- fix issue where triggers via renderTrigger were not being informed on hover events
  • Loading branch information
TerrenceLJones committed May 1, 2020
1 parent 0134ff3 commit c9714eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
21 changes: 19 additions & 2 deletions src/components/Dropdown/V2/Dropdown.Trigger.tsx
Expand Up @@ -6,7 +6,10 @@ import propConnect from '../../PropProvider/propConnect'
import { TriggerUI } from './Dropdown.css.js'
import Keys from '../../../constants/Keys'
import { classNames } from '../../../utilities/classNames'
import { namespaceComponent } from '../../../utilities/component'
import {
namespaceComponent,
renderRenderPropComponent,
} from '../../../utilities/component'
import { noop } from '../../../utilities/other'
import { COMPONENT_KEY } from './Dropdown.utils'

Expand Down Expand Up @@ -42,6 +45,8 @@ export class Trigger extends React.PureComponent<Props> {
toggleOpen: noop,
}

state = { isHovered: false }

handleOnClick = (event: Event) => {
this.props.onClick(event)
this.props.toggleOpen()
Expand Down Expand Up @@ -87,6 +92,14 @@ export class Trigger extends React.PureComponent<Props> {
}
}

renderChildren() {
const { children } = this.props
const { isHovered } = this.state
const renderedChildren = renderRenderPropComponent(children, { isHovered })

return renderedChildren ? renderedChildren : children
}

render() {
const {
className,
Expand Down Expand Up @@ -118,7 +131,11 @@ export class Trigger extends React.PureComponent<Props> {
onFocus={onFocus}
onClick={this.handleOnClick}
onKeyDown={this.handleOnKeyDown}
/>
onMouseOver={() => this.setState({ isHovered: true })}
onMouseLeave={() => this.setState({ isHovered: false })}
>
{this.renderChildren()}
</TriggerUI>
)
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/components/Dropdown/V2/Dropdown.css.js
Expand Up @@ -14,13 +14,17 @@ export const MenuContainerUI = styled('div')`
position: absolute;
&.is-dropUp {
bottom: 100%;
bottom: calc(100% + 5px);
}
&.is-dropLeft {
right: 0%;
}
&:not(.is-dropUp) {
top: 5px;
}
.c-DropdownV2Block + .c-DropdownV2Block {
border-top: 1px solid ${getColor('grey.600')};
}
Expand Down

0 comments on commit c9714eb

Please sign in to comment.