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

Commit

Permalink
feat: add prop to disable popup menu Closes issues: disable-popup-menu (
Browse files Browse the repository at this point in the history
  • Loading branch information
sievertknorrblad authored Jan 2, 2019
1 parent 8ab2874 commit 7b27066
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/components/popup-menu/popup-menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ class PopupMenu extends Component {
buttonLabel,
buttonID,
isOpen: isOpenFromProps,
disabled,
theme,
} = this.props;
const { isOpen } = this.state;
const open = isOpenFromProps !== null ? isOpenFromProps : isOpen;
const open = !disabled && (isOpenFromProps !== null ? isOpenFromProps : isOpen);
let label = null;
if (typeof buttonLabel === 'string') label = buttonLabel;
else if (typeof buttonLabel === 'object' && buttonLabel !== null) {
Expand All @@ -114,12 +116,20 @@ class PopupMenu extends Component {
if (this.buttonElement) this.buttonElement.focus();
this.onToggle();
}}
disabled={disabled}
ref={this.setButtonRef}
onKeyDown={this.onKeyDown}
onFocus={this.onFocus}
onBlur={this.onBlur}
>
{toggleButton || <Icon.VerticalEllipsis height={28} width={28} stroke="currentColor" fill="currentColor" />}
{toggleButton || (
<Icon.VerticalEllipsis
height={28}
width={28}
stroke={disabled ? theme.palette.action.disabled : 'currentColor'}
fill={disabled ? theme.palette.action.disabled : 'currentColor'}
/>
)}
</button>
<PopupMenuList
aria-labelledby={id}
Expand All @@ -142,6 +152,8 @@ class PopupMenu extends Component {
}

PopupMenu.propTypes = {
/** @ignore */
theme: PropTypes.object.isRequired,
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/** Will be deprecated. Overrides, but does not change the internal state. */
isOpen: PropTypes.bool,
Expand Down Expand Up @@ -183,6 +195,8 @@ PopupMenu.propTypes = {
exit: PropTypes.number,
/** The content of the toggle button, defaults to `VerticalEllipsis` from the Icon set. */
toggleButton: PropTypes.node,
/** Disables the popup menu */
disabled: PropTypes.bool,
maxHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};

Expand All @@ -195,6 +209,7 @@ PopupMenu.defaultProps = {
exit: 100,
toggleButton: null,
maxHeight: 'none',
disabled: false,
};

export { PopupMenu as Component, styles };
Expand Down

0 comments on commit 7b27066

Please sign in to comment.