Skip to content

Commit bc92a72

Browse files
authored
Merge pull request #92 from toggle-corp/feature/popup-default-visible
Add default shown in popup
2 parents 4e3c921 + d6167a7 commit bc92a72

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/components/PopupButton/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface PopupButtonProps<N extends number | string | undefined> extends
1818
} | null>;
1919
persistent: boolean;
2020
arrowHidden?: boolean;
21+
defaultShown?: boolean;
2122
}
2223
function PopupButton<N extends number | string | undefined>(props: PopupButtonProps<N>) {
2324
const {
@@ -30,13 +31,14 @@ function PopupButton<N extends number | string | undefined>(props: PopupButtonPr
3031
componentRef,
3132
arrowHidden,
3233
persistent,
34+
defaultShown,
3335
...otherProps
3436
} = props;
3537

3638
const buttonRef = React.useRef<HTMLButtonElement>(null);
3739
const popupRef = React.useRef<HTMLDivElement>(null);
3840

39-
const [popupShown, setPopupShown] = React.useState(false);
41+
const [popupShown, setPopupShown] = React.useState(defaultShown ?? false);
4042

4143
useEffect(
4244
() => {
@@ -58,7 +60,7 @@ function PopupButton<N extends number | string | undefined>(props: PopupButtonPr
5860

5961
const handleShowPopup = useCallback(
6062
() => {
61-
setPopupShown(true);
63+
setPopupShown((prevState) => !prevState);
6264
},
6365
[],
6466
);

src/stories/PopupButton.stories.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,20 @@ const Template: Story<PopupButtonProps<string>> = (args) => (
4242
<PopupButton {...args} />
4343
);
4444

45+
export const DefaultShown = Template.bind({});
46+
DefaultShown.args = {
47+
label: 'PopupButton',
48+
children: <MenuItems />,
49+
transparent: true,
50+
defaultShown: true,
51+
};
52+
4553
export const Default = Template.bind({});
4654
Default.args = {
4755
label: 'PopupButton',
4856
transparent: true,
4957
children: <MenuItems />,
5058
};
51-
5259
export const Disabled = Template.bind({});
5360
Disabled.args = {
5461
label: 'PopupButton',

0 commit comments

Comments
 (0)