Skip to content

Commit

Permalink
feat(Dropdown): add positionFixed property
Browse files Browse the repository at this point in the history
  • Loading branch information
ej9x committed Aug 19, 2019
1 parent 5fe34cc commit 3878492
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/components/Dropdown/DropdownBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type DropdownBodyProps = {
pin?: 'left' | 'right',
/** Set body offset relative target */
offset?: PropSizes,
/** Use fixed position instead of absolute */
positionFixed?: boolean,
/** Manual set width */
width?: number,
/** Popper js option https://popper.js.org/popper-documentation.html#modifiers..preventOverflow */
Expand Down Expand Up @@ -83,6 +85,7 @@ const DropdownBody = dropdownBodyEnhancer(
isOpen: false,
forceRender: false,
withPortal: false,
positionFixed: false,
closeOnClickOutside: true,
}

Expand Down Expand Up @@ -128,7 +131,7 @@ const DropdownBody = dropdownBodyEnhancer(


render() {
const { withPortal, forceRender, dropdown: { isOpen }, ...rest } = this.props;
const { withPortal, forceRender, positionFixed, dropdown: { isOpen }, ...rest } = this.props;

const popperPlacement = this.getPopperPlacement();
const popperModifiers = this.getPopperModifiers();
Expand All @@ -142,6 +145,7 @@ const DropdownBody = dropdownBodyEnhancer(
<Popper
placement={ popperPlacement }
modifiers={ popperModifiers }
positionFixed={ positionFixed }
>
{ ({ ref, style, placement }) => (
<DropdownBodyTag
Expand Down
17 changes: 15 additions & 2 deletions src/components/Dropdown/Dropdowon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as React from 'react';
import { Dropdown } from './';
import { Popper } from 'react-popper';


describe('<Dropdown />', () => {
Expand All @@ -19,7 +20,19 @@ describe('<Dropdown />', () => {
});


it('should open and close dropdwon by changing the props', () => {
it('should pass props to Popper component', () => {
const wrapper = mount(
<Dropdown isOpen>
<Dropdown.Head><div /></Dropdown.Head>
<Dropdown.Body positionFixed><div /></Dropdown.Body>
</Dropdown>,
);

expect(wrapper.find(Popper).props().positionFixed).toBeTruthy();
});


it('should open and close dropdown by changing the props', () => {
const wrapper = mount(
<Dropdown isOpen={ false }>
<Dropdown.Head>Head</Dropdown.Head>
Expand Down Expand Up @@ -85,7 +98,7 @@ describe('<Dropdown />', () => {
});


it('shouldn\'t open and close dropdwon when disabled=true', () => {
it('shouldn\'t open and close dropdown when disabled=true', () => {
const wrapper = mount(
<Dropdown>
<Dropdown.Head disabled>Head</Dropdown.Head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ exports[`<Dropdown /> should render dropdown 1`] = `
padding="none"
pin="left"
placement="bottom"
positionFixed={false}
preventDefault={false}
stopPropagation={false}
withPortal={false}
Expand Down

0 comments on commit 3878492

Please sign in to comment.