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

Fix EntitiesSavedStates panel dialog props. #67351

Merged
Merged
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
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.
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved

_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
Loading