Skip to content

Commit

Permalink
feat: add ability to disable SelectMenu (#3138)
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto committed Jul 17, 2024
1 parent cecbc9f commit c579d88
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Menu/SelectMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function SelectMenu({
children,
className,
variant,
disabled,
...props
}) {
const [triggerTarget, setTriggerTarget] = useState(null);
Expand Down Expand Up @@ -89,6 +90,7 @@ function SelectMenu({
variant={variant}
iconAfter={ExpandMore}
onClick={open}
disabled={disabled}
>
{selected !== undefined && children[selected] ? children[selected].props.children : defaultMessage}
</Button>
Expand Down Expand Up @@ -131,12 +133,15 @@ SelectMenu.propTypes = {
className: PropTypes.string,
/** Specifies variant to use. */
variant: PropTypes.string,
/** Specifies if the `SelectMenu` is disabled. */
disabled: PropTypes.bool,
};

SelectMenu.defaultProps = {
defaultMessage: SELECT_MENU_DEFAULT_MESSAGE,
className: undefined,
variant: 'outline-primary',
disabled: false,
};

const SelectMenuWithDeprecatedProp = withDeprecatedProps(SelectMenu, 'SelectMenu', {
Expand Down
6 changes: 6 additions & 0 deletions src/Menu/SelectMenu.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ describe('correct rendering', () => {
const button = screen.getByRole('button');
expect(button).toHaveClass('btn-brand');
});

it('renders as disabled', () => {
render(DefaultSelectMenu({ disabled: true }));
const button = screen.getByRole('button');
expect(button).toBeDisabled();
});
});

describe('mouse behavior & keyboard behavior', () => {
Expand Down
8 changes: 8 additions & 0 deletions src/Menu/select-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@ The ``Modal`` brings focus to the first menu element upon the click of the trigg
<MenuItem>M. Hortens</MenuItem>
</SelectMenu>
```

## Disabled

```jsx live
<SelectMenu disabled>
<MenuItem>A Menu Item</MenuItem>
</SelectMenu>
```

0 comments on commit c579d88

Please sign in to comment.