Skip to content

Commit

Permalink
feat: defaultVisible prop added
Browse files Browse the repository at this point in the history
  • Loading branch information
jpranays committed Jun 19, 2024
1 parent 825a52d commit 5d4fb3a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
17 changes: 16 additions & 1 deletion components/lib/dialog/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ export const Dialog = React.forwardRef((inProps, ref) => {
const [bindDocumentDragEndListener, unbindDocumentDragEndListener] = useEventListener({ type: 'mouseup', target: () => window.document, listener: (event) => onDragEnd(event) });

const onClose = (event) => {
props.onHide();
if (props.onHide) {
props.onHide();
}

if (props.defaultVisible && isCloseOnEscape) {
setVisibleState(false);
setMaskVisibleState(false);
}

event.preventDefault();
};

Expand Down Expand Up @@ -406,6 +414,13 @@ export const Dialog = React.forwardRef((inProps, ref) => {
}
}, [maskVisibleState]);

useUpdateEffect(() => {
if (props.defaultVisible) {
setVisibleState(true);
setMaskVisibleState(true);
}
}, [props.defaultVisible]);

useUpdateEffect(() => {
updateGlobalDialogsRegistry(true);
}, [shouldBlockScroll, visibleState]);
Expand Down
1 change: 1 addition & 0 deletions components/lib/dialog/DialogBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export const DialogBase = ComponentBase.extend({
showHeader: true,
style: null,
transitionOptions: null,
defaultVisible: false,
visible: false,
children: undefined
},
Expand Down
7 changes: 6 additions & 1 deletion components/lib/dialog/dialog.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ export interface DialogProps {
* The properties of CSSTransition can be customized, except for "nodeRef" and "in" properties.
*/
transitionOptions?: CSSTransitionProps | undefined;
/**
* Specifies the default visibility of the dialog.
* @defaultValue false
*/
defaultVisible?: boolean | undefined;
/**
* Specifies the visibility of the dialog.
* @defaultValue false
Expand Down Expand Up @@ -396,7 +401,7 @@ export interface DialogProps {
/**
* Callback to invoke when dialog is hidden (Required).
*/
onHide(): void;
onHide?(): void;
/**
* Callback to invoke when the mask is clicked.
* @param {React.MouseEvent<HTMLElement>} event - Browser event.
Expand Down

0 comments on commit 5d4fb3a

Please sign in to comment.