Skip to content

Commit

Permalink
Add menuId prop to allow passing of ID to dropdown menu (#375)
Browse files Browse the repository at this point in the history
* Add menuId prop to allow passing of ID to dropdown menu

* Revert package-lock.json
  • Loading branch information
kennethnym authored Feb 9, 2022
1 parent 12577c0 commit 82d13fc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/components/dropdown/__test__/dropdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,12 @@ describe('Dropdown component', () => {
);
expect(component.find('span').text()).toEqual('Item');
});
it('Should pass specified ID to the menu component', () => {
const component = shallow(
<Dropdown menuId="test-id">
<Dropdown.Item value="value">Item</Dropdown.Item>
</Dropdown>,
);
expect(component).toMatchSnapshot();
});
});
16 changes: 12 additions & 4 deletions src/components/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const Dropdown = ({
icon,
domRef,
disabled,
menuId,
...props
}) => {
const ref = useRef(domRef);
Expand Down Expand Up @@ -101,12 +102,17 @@ const Dropdown = ({
});
}}
>
<Button disabled={disabled} color={color}>
<Button
disabled={disabled}
color={color}
aria-haspopup
aria-controls={menuId}
>
<span>{current}</span>
{icon}
</Button>
</div>
<div className="dropdown-menu" id="dropdown-menu" role="menu">
<div className="dropdown-menu" id={menuId} role="menu">
<div className="dropdown-content">{childrenArray}</div>
</div>
</Element>
Expand Down Expand Up @@ -174,13 +180,15 @@ Dropdown.propTypes = {
*/
icon: PropTypes.node,
/**
* Additional CSS classes to pass to `<Dropdown />`.
* They will sit alongside pre-applied bulma classes.
* Specify the id of the menu component.
* Default is "dropdown-menu".
*/
menuId: PropTypes.string,
};

Dropdown.defaultProps = {
closeOnSelect: true,
menuId: 'dropdown-menu',
};

export default Dropdown;
1 change: 1 addition & 0 deletions src/components/dropdown/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface DropdownProps<T> {
align?: 'right';
icon?: React.ReactNode;
disabled?: boolean;
menuId?: string;
}

interface DropdownItemProps<T> {
Expand Down

0 comments on commit 82d13fc

Please sign in to comment.