Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance: Added close on outside click flag & updated save post panel #67327

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/compose/src/hooks/use-dialog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ type DialogOptions = {
*/
constrainTabbing?: boolean;
onClose?: () => void;
/**
* Whether to close on click outside.
*
* @default true
*/
closeOnOutsideClick?: boolean;
/**
* Use the `onClose` prop instead.
*
Expand Down Expand Up @@ -67,7 +73,10 @@ type useDialogReturn = [
*/
function useDialog( options: DialogOptions ): useDialogReturn {
const currentOptions = useRef< DialogOptions | undefined >();
const { constrainTabbing = options.focusOnMount !== false } = options;
const {
constrainTabbing = options.focusOnMount !== false,
closeOnOutsideClick = true,
} = options;
useEffect( () => {
currentOptions.current = options;
}, Object.values( options ) );
Expand All @@ -79,7 +88,7 @@ function useDialog( options: DialogOptions ): useDialogReturn {
// for the Popover component otherwise, the onClose should be enough.
if ( currentOptions.current?.__unstableOnClose ) {
currentOptions.current.__unstableOnClose( 'focus-outside', event );
} else if ( currentOptions.current?.onClose ) {
} else if ( currentOptions.current?.onClose && closeOnOutsideClick ) {
currentOptions.current.onClose();
}
} );
Expand Down
17 changes: 14 additions & 3 deletions packages/edit-site/src/components/save-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,20 @@ const EntitiesSavedStatesForPreview = ( { onClose } ) => {
);
};

const _EntitiesSavedStates = ( { onClose, renderDialog = undefined } ) => {
const _EntitiesSavedStates = ( {
onClose,
renderDialog = undefined,
closeOnOutsideClick = true,
} ) => {
if ( isPreviewingTheme() ) {
return <EntitiesSavedStatesForPreview onClose={ onClose } />;
}
return (
<EntitiesSavedStates close={ onClose } renderDialog={ renderDialog } />
<EntitiesSavedStates
close={ onClose }
renderDialog={ renderDialog }
closeOnOutsideClick={ closeOnOutsideClick }
/>
);
};

Expand Down Expand Up @@ -129,7 +137,10 @@ export default function SavePanel() {
'Save site, content, and template changes'
) }
>
<_EntitiesSavedStates onClose={ onClose } />
<_EntitiesSavedStates
onClose={ onClose }
closeOnOutsideClick={ false }
/>
</Modal>
) : null;
}
Expand Down
1 change: 1 addition & 0 deletions packages/editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ _Parameters_
- _props_ `Object`: The component props.
- _props.close_ `Function`: The function to close the dialog.
- _props.renderDialog_ `Function`: The function to render the dialog.
- _props.closeOnOutsideClick_ `boolean`: Whether to close if outside click is detected.

_Returns_

Expand Down
12 changes: 9 additions & 3 deletions packages/editor/src/components/entities-saved-states/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,24 @@ function identity( values ) {
/**
* Renders the component for managing saved states of entities.
*
* @param {Object} props The component props.
* @param {Function} props.close The function to close the dialog.
* @param {Function} props.renderDialog The function to render the dialog.
* @param {Object} props The component props.
* @param {Function} props.close The function to close the dialog.
* @param {Function} props.renderDialog The function to render the dialog.
* @param {boolean} props.closeOnOutsideClick Whether to close if outside click is detected.
*
* @return {JSX.Element} The rendered component.
*/
export default function EntitiesSavedStates( {
close,
renderDialog = undefined,
closeOnOutsideClick = true,
} ) {
const isDirtyProps = useIsDirty();
return (
<EntitiesSavedStatesExtensible
close={ close }
renderDialog={ renderDialog }
closeOnOutsideClick={ closeOnOutsideClick }
{ ...isDirtyProps }
/>
);
Expand All @@ -63,6 +66,7 @@ export default function EntitiesSavedStates( {
* @param {boolean} props.isDirty Flag indicating if there are dirty entities.
* @param {Function} props.setUnselectedEntities Function to set unselected entities.
* @param {Array} props.unselectedEntities Array of unselected entities.
* @param {boolean} props.closeOnOutsideClick Whether to close if outside click is detected.
*
* @return {JSX.Element} The rendered component.
*/
Expand All @@ -77,6 +81,7 @@ export function EntitiesSavedStatesExtensible( {
isDirty,
setUnselectedEntities,
unselectedEntities,
closeOnOutsideClick = true,
} ) {
const saveButtonRef = useRef();
const { saveDirtyEntities } = unlock( useDispatch( editorStore ) );
Expand Down Expand Up @@ -111,6 +116,7 @@ export function EntitiesSavedStatesExtensible( {

const [ saveDialogRef, saveDialogProps ] = useDialog( {
onClose: () => dismissPanel(),
closeOnOutsideClick,
} );
const dialogLabel = useInstanceId( EntitiesSavedStatesExtensible, 'label' );
const dialogDescription = useInstanceId(
Expand Down
Loading