Skip to content

Commit

Permalink
Merge pull request #32 from Arize-ai/close-on-blur
Browse files Browse the repository at this point in the history
Make popover default to close on blur
  • Loading branch information
mikeldking authored Aug 19, 2021
2 parents 2f2bb5c + 0a0d19c commit 3d38961
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 53 deletions.
7 changes: 7 additions & 0 deletions src/popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import { popoverCSS } from './styles';
export interface PopoverProps extends HTMLAttributes<HTMLElement> {
onClose?: () => void;
isOpen?: boolean;
/**
* Whether or not the popover should close when the component loses focus
* @default true
*/
shouldCloseOnBlur?: boolean;
children: ReactNode;
placement?: PlacementAxis;
}
Expand All @@ -22,6 +27,7 @@ function Popover(props: PopoverProps, ref: DOMRef<HTMLDivElement>) {
children,
isOpen = false,
onClose,
shouldCloseOnBlur = true,
style,
...otherProps
} = props;
Expand All @@ -32,6 +38,7 @@ function Popover(props: PopoverProps, ref: DOMRef<HTMLDivElement>) {
{
onClose,
isOpen,
shouldCloseOnBlur,
isDismissable: true,
},
domRef
Expand Down
53 changes: 0 additions & 53 deletions stories/PopoverTrigger.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,57 +105,4 @@ const Template: Story<PopoverTriggerProps> = args => {
// https://storybook.js.org/docs/react/workflows/unit-testing
export const Default = Template.bind({});

const ControlledTemplate: Story<PopoverTriggerProps> = args => {
const [selectedId, setSelectedId] = useState<string>(null);
return (
<Provider>
<ul style={{ listStyle: 'none', marginLeft: '300px' }}>
{['one', 'two', 'three'].map((id, index) => {
return (
<li key={index} style={{ margin: '24px 0' }}>
<PopoverTrigger
placement="left top"
isOpen={id === selectedId}
onOpenChange={isOpen => {
if (isOpen && id !== selectedId) {
setSelectedId(id);
} else if (!isOpen && id == selectedId) {
setSelectedId(null);
}
}}
>
<ActionButton>{id}</ActionButton>
<Card
title="Popover Card Title"
bodyStyle={{ padding: 0, minWidth: 300 }}
>
<ul
css={css`
list-style: none;
margin: 0;
padding: 0;
& > li {
padding: 16px 24px;
&:not(:last-child) {
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
}
`}
>
<li>Item One</li>
<li>Item Two</li>
<li>Item Three</li>
</ul>
</Card>
</PopoverTrigger>
</li>
);
})}
</ul>
</Provider>
);
};

export const Controlled = ControlledTemplate.bind({});

Default.args = {};

0 comments on commit 3d38961

Please sign in to comment.