Skip to content

Commit

Permalink
feat: dropdown: add prop to disable closing on clicking outside
Browse files Browse the repository at this point in the history
  • Loading branch information
ychhabra-eightfold committed Aug 22, 2022
1 parent aa1d6ca commit b3c7d23
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const Dropdown: FC<DropdownProps> = React.memo(
showDropdown,
disabled,
closeOnDropdownClick = true,
closeOnOutsideClick = true,
visible,
onClickOutside,
}) => {
Expand Down Expand Up @@ -93,7 +94,9 @@ export const Dropdown: FC<DropdownProps> = React.memo(
useOnClickOutside(
refs.reference,
(e) => {
toggle(false)(e);
if (closeOnOutsideClick) {
toggle(false)(e);
}
onClickOutside?.(e);
},
mergedVisible
Expand Down
12 changes: 12 additions & 0 deletions src/components/Dropdown/Dropdown.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ export interface DropdownProps {
* @default true
*/
closeOnDropdownClick?: boolean;
/**
* Should close dropdown on click outside
* @default true
*/
closeOnOutsideClick?: boolean;
/**
* Manually control visibility of the dropdown
*/
visible?: boolean;
/**
* Callback method fired on outside click on dropdown
* @param event
*/
onClickOutside?: (event: MouseEvent) => void;
}
7 changes: 1 addition & 6 deletions src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import { MenuItem } from './MenuItem/MenuItem';
import { MenuItemType } from './MenuItem/MenuItem.types';
import { mergeClasses } from '../../shared/utilities';
import { Stack } from '../Stack';
import {
ButtonShape,
ButtonSize,
NeutralButton,
PrimaryButton,
} from '../Button';
import { ButtonSize, NeutralButton, PrimaryButton } from '../Button';

import styles from './menu.module.scss';

Expand Down

0 comments on commit b3c7d23

Please sign in to comment.