File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff 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}
2223function 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 ) ;
Original file line number Diff line number Diff 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+
4553export const Default = Template . bind ( { } ) ;
4654Default . args = {
4755 label : 'PopupButton' ,
4856 transparent : true ,
4957 children : < MenuItems /> ,
5058} ;
51-
5259export const Disabled = Template . bind ( { } ) ;
5360Disabled . args = {
5461 label : 'PopupButton' ,
You can’t perform that action at this time.
0 commit comments