Skip to content

Commit

Permalink
Fix EntitiesSavedStates panel dialog props. (WordPress#67351)
Browse files Browse the repository at this point in the history
* Fix EntitiesSavedStates panel dialog props.

* Remove renderDialog default value.

Co-authored-by: afercia <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
Co-authored-by: Mayank-Tripathi32 <[email protected]>
Co-authored-by: jameskoster <[email protected]>
  • Loading branch information
5 people authored and im3dabasia committed Dec 4, 2024
1 parent 64ccdca commit 1054034
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
12 changes: 9 additions & 3 deletions packages/edit-site/src/components/save-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const { EntitiesSavedStatesExtensible, NavigableRegion } =
unlock( privateApis );
const { useLocation } = unlock( routerPrivateApis );

const EntitiesSavedStatesForPreview = ( { onClose } ) => {
const EntitiesSavedStatesForPreview = ( { onClose, renderDialog } ) => {
const isDirtyProps = useEntitiesSavedStatesIsDirty();
let activateSaveLabel;
if ( isDirtyProps.isDirty ) {
Expand Down Expand Up @@ -75,14 +75,20 @@ const EntitiesSavedStatesForPreview = ( { onClose } ) => {
onSave,
saveEnabled: true,
saveLabel: activateSaveLabel,
renderDialog,
} }
/>
);
};

const _EntitiesSavedStates = ( { onClose, renderDialog = undefined } ) => {
const _EntitiesSavedStates = ( { onClose, renderDialog } ) => {
if ( isPreviewingTheme() ) {
return <EntitiesSavedStatesForPreview onClose={ onClose } />;
return (
<EntitiesSavedStatesForPreview
onClose={ onClose }
renderDialog={ renderDialog }
/>
);
}
return (
<EntitiesSavedStates close={ onClose } renderDialog={ renderDialog } />
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,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.renderDialog_ `boolean`: Whether to render the component with modal dialog behavior.

_Returns_

Expand Down
15 changes: 6 additions & 9 deletions packages/editor/src/components/entities-saved-states/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@ function identity( values ) {
*
* @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.renderDialog Whether to render the component with modal dialog behavior.
*
* @return {React.ReactNode} The rendered component.
*/
export default function EntitiesSavedStates( {
close,
renderDialog = undefined,
} ) {
export default function EntitiesSavedStates( { close, renderDialog } ) {
const isDirtyProps = useIsDirty();
return (
<EntitiesSavedStatesExtensible
Expand All @@ -58,7 +55,7 @@ export default function EntitiesSavedStates( {
* @param {Function} props.onSave Function to call when saving entities.
* @param {boolean} props.saveEnabled Flag indicating if save is enabled.
* @param {string} props.saveLabel Label for the save button.
* @param {Function} props.renderDialog Function to render a custom dialog.
* @param {boolean} props.renderDialog Whether to render the component with modal dialog behavior.
* @param {Array} props.dirtyEntityRecords Array of dirty entity records.
* @param {boolean} props.isDirty Flag indicating if there are dirty entities.
* @param {Function} props.setUnselectedEntities Function to set unselected entities.
Expand All @@ -72,7 +69,7 @@ export function EntitiesSavedStatesExtensible( {
onSave = identity,
saveEnabled: saveEnabledProp = undefined,
saveLabel = __( 'Save' ),
renderDialog = undefined,
renderDialog,
dirtyEntityRecords,
isDirty,
setUnselectedEntities,
Expand Down Expand Up @@ -120,8 +117,8 @@ export function EntitiesSavedStatesExtensible( {

return (
<div
ref={ saveDialogRef }
{ ...saveDialogProps }
ref={ renderDialog ? saveDialogRef : undefined }
{ ...( renderDialog && saveDialogProps ) }
className="entities-saved-states__panel"
role={ renderDialog ? 'dialog' : undefined }
aria-labelledby={ renderDialog ? dialogLabel : undefined }
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/components/post-publish-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export class PostPublishButton extends Component {
isBusy: ! isAutoSaving && isSaving,
variant: 'primary',
onClick: this.createOnClick( onClickButton ),
'aria-haspopup': hasNonPostEntityChanges ? 'dialog' : undefined,
};

const toggleProps = {
Expand All @@ -161,6 +162,7 @@ export class PostPublishButton extends Component {
variant: 'primary',
size: 'compact',
onClick: this.createOnClick( onClickToggle ),
'aria-haspopup': hasNonPostEntityChanges ? 'dialog' : undefined,
};
const componentProps = isToggle ? toggleProps : buttonProps;
return (
Expand Down
6 changes: 5 additions & 1 deletion packages/editor/src/components/save-publish-panels/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export default function SavePublishPanels( {
variant="secondary"
onClick={ openEntitiesSavedStates }
aria-expanded={ false }
aria-haspopup="dialog"
disabled={ ! isDirty }
accessibleWhenDisabled
>
Expand All @@ -102,7 +103,10 @@ export default function SavePublishPanels( {
return (
<>
{ isEntitiesSavedStatesOpen && (
<EntitiesSavedStates close={ closeEntitiesSavedStates } />
<EntitiesSavedStates
close={ closeEntitiesSavedStates }
renderDialog
/>
) }
<Slot bubblesVirtually />
{ ! isEntitiesSavedStatesOpen && unmountableContent }
Expand Down

0 comments on commit 1054034

Please sign in to comment.