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

Document settings: improve accessibility of "Status & visibility" controls #24024

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
4 changes: 4 additions & 0 deletions packages/components/src/panel/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
.components-panel__body-toggle.components-button {
position: relative;
padding: $grid-unit-20;

// Stop text from overlapping the expand/collapse icon.
padding-right: $grid-unit-60;

outline: none;
width: 100%;
font-weight: 500;
Expand Down
8 changes: 8 additions & 0 deletions packages/e2e-test-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,14 @@ _Returns_

Opens the publish panel.

<a name="openSidebarPanel" href="#openSidebarPanel">#</a> **openSidebarPanel**

Opens a sidebar panel with the provided title.

_Parameters_

- _panelTitle_ `string`: The name of sidebar panel.

<a name="pressKeyTimes" href="#pressKeyTimes">#</a> **pressKeyTimes**

Presses the given keyboard key a number of times in sequence.
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-test-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export {
} from './observe-focus-loss';
export { openDocumentSettingsSidebar } from './open-document-settings-sidebar';
export { openPublishPanel } from './open-publish-panel';
export { openSidebarPanel } from './open-sidebar-panel';
export { trashAllPosts } from './posts';
export { pressKeyTimes } from './press-key-times';
export {
Expand Down
21 changes: 21 additions & 0 deletions packages/e2e-test-utils/src/open-sidebar-panel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Internal dependencies
*/
import { findSidebarPanelToggleButtonWithTitle } from './find-sidebar-panel-toggle-button-with-title';

/**
* Opens a sidebar panel with the provided title.
*
* @param {string} panelTitle The name of sidebar panel.
*/
export async function openSidebarPanel( panelTitle ) {
const panelToggle = await findSidebarPanelToggleButtonWithTitle(
panelTitle
);
const panelIsCollapsed = await panelToggle.evaluate(
( node ) => node.getAttribute( 'aria-expanded' ) === 'false'
);
if ( panelIsCollapsed ) {
await panelToggle.click();
}
}
46 changes: 34 additions & 12 deletions packages/e2e-tests/specs/editor/various/datepicker.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/**
* WordPress dependencies
*/
import { createNewPost, changeSiteTimezone } from '@wordpress/e2e-test-utils';
import {
createNewPost,
changeSiteTimezone,
findSidebarPanelToggleButtonWithTitle,
} from '@wordpress/e2e-test-utils';

async function getInputValue( selector ) {
return page.$eval( selector, ( element ) => element.value );
Expand Down Expand Up @@ -47,9 +51,12 @@ function formatDatePickerValues( {
}

async function getPublishingDate() {
return page.$eval(
'.edit-post-post-schedule__toggle',
( dateLabel ) => dateLabel.textContent
const panelToggle = await findSidebarPanelToggleButtonWithTitle(
'Publish date:'
);
return panelToggle.$eval(
'.editor-post-publish-panel__link',
( publishDateSpan ) => publishDateSpan.textContent
);
}

Expand All @@ -66,22 +73,31 @@ describe.each( [ [ 'UTC-10' ], [ 'UTC' ], [ 'UTC+10' ] ] )(
} );

it( 'should show the publishing date as "Immediately" if the date is not altered', async () => {
// Open the datepicker.
const panelToggle = await findSidebarPanelToggleButtonWithTitle(
'Publish date:'
);
await panelToggle.click();

const publishingDate = await getPublishingDate();

expect( publishingDate ).toEqual( 'Immediately' );
} );

it( 'should show the publishing date if the date is in the past', async () => {
// Open the datepicker.
await page.click( '.edit-post-post-schedule__toggle' );
const panelToggle = await findSidebarPanelToggleButtonWithTitle(
'Publish date:'
);
await panelToggle.click();

// Change the publishing date to a year in the past.
await page.click( '.components-datetime__time-field-year' );
await page.keyboard.press( 'ArrowDown' );
const datePickerValues = await getDatePickerValues();

// Close the datepicker.
await page.click( '.edit-post-post-schedule__toggle' );
await panelToggle.click();

const publishingDate = await getPublishingDate();

Expand All @@ -92,15 +108,18 @@ describe.each( [ [ 'UTC-10' ], [ 'UTC' ], [ 'UTC+10' ] ] )(

it( 'should show the publishing date if the date is in the future', async () => {
// Open the datepicker.
await page.click( '.edit-post-post-schedule__toggle' );
const panelToggle = await findSidebarPanelToggleButtonWithTitle(
'Publish date:'
);
await panelToggle.click();

// Change the publishing date to a year in the future.
await page.click( '.components-datetime__time-field-year' );
await page.keyboard.press( 'ArrowUp' );
const datePickerValues = await getDatePickerValues();

// Close the datepicker.
await page.click( '.edit-post-post-schedule__toggle' );
await panelToggle.click();

const publishingDate = await getPublishingDate();

Expand All @@ -113,19 +132,22 @@ describe.each( [ [ 'UTC-10' ], [ 'UTC' ], [ 'UTC+10' ] ] )(

it( `should show the publishing date as "Immediately" if the date is cleared`, async () => {
// Open the datepicker.
await page.click( '.edit-post-post-schedule__toggle' );
const panelToggle = await findSidebarPanelToggleButtonWithTitle(
'Publish date:'
);
await panelToggle.click();

// Change the publishing date to a year in the future.
await page.click( '.components-datetime__time-field-year' );
await page.keyboard.press( 'ArrowUp' );

// Close the datepicker.
await page.click( '.edit-post-post-schedule__toggle' );
await panelToggle.click();

// Open the datepicker.
await page.click( '.edit-post-post-schedule__toggle' );
await panelToggle.click();

// Clear the date
// Clear the date.
await page.click( '.components-datetime__date-reset-button' );

const publishingDate = await getPublishingDate();
Expand Down
3 changes: 3 additions & 0 deletions packages/e2e-tests/specs/editor/various/new-post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
activatePlugin,
createNewPost,
deactivatePlugin,
openSidebarPanel,
} from '@wordpress/e2e-test-utils';

describe( 'new editor state', () => {
Expand Down Expand Up @@ -34,6 +35,8 @@ describe( 'new editor state', () => {
);
expect( postPreviewButton ).not.toBeNull();
// Should display the Post Formats UI.
await openSidebarPanel( 'Post Format' );
await page.waitForSelector( '.editor-post-format' );
const postFormatsUi = await page.$( '.editor-post-format' );
expect( postFormatsUi ).not.toBeNull();
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
setBrowserViewport,
createNewPost,
openDocumentSettingsSidebar,
openSidebarPanel,
} from '@wordpress/e2e-test-utils';

describe( 'Post visibility', () => {
Expand All @@ -19,7 +20,7 @@ describe( 'Post visibility', () => {

await openDocumentSettingsSidebar();

await page.click( '.edit-post-post-visibility__toggle' );
await openSidebarPanel( 'Visibility:' );

const [ privateLabel ] = await page.$x(
'//label[text()="Private"]'
Expand All @@ -45,7 +46,7 @@ describe( 'Post visibility', () => {
await openDocumentSettingsSidebar();

// Set a publish date for the next month.
await page.click( '.edit-post-post-schedule__toggle' );
await openSidebarPanel( 'Publish date:' );
await page.click(
'div[aria-label="Move forward to switch to the next month."]'
);
Expand All @@ -55,7 +56,7 @@ describe( 'Post visibility', () => {
)
)[ 0 ].click();

await page.click( '.edit-post-post-visibility__toggle' );
await openSidebarPanel( 'Visibility:' );

const [ privateLabel ] = await page.$x( '//label[text()="Private"]' );
await privateLabel.click();
Expand Down
9 changes: 6 additions & 3 deletions packages/e2e-tests/specs/editor/various/scheduling.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/**
* WordPress dependencies
*/
import { createNewPost, changeSiteTimezone } from '@wordpress/e2e-test-utils';
import {
changeSiteTimezone,
createNewPost,
openSidebarPanel,
} from '@wordpress/e2e-test-utils';

async function getPublishButtonText() {
return page.$eval(
Expand Down Expand Up @@ -55,8 +59,7 @@ describe( 'Scheduling', () => {

it( 'Should keep date time UI focused when the previous and next month buttons are clicked', async () => {
await createNewPost();

await page.click( '.edit-post-post-schedule__toggle' );
await openSidebarPanel( 'Publish date:' );
await page.click(
'div[aria-label="Move backward to switch to the previous month."]'
);
Expand Down
39 changes: 32 additions & 7 deletions packages/e2e-tests/specs/editor/various/sidebar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
* WordPress dependencies
*/
import {
activatePlugin,
clearLocalStorage,
createNewPost,
deactivatePlugin,
findSidebarPanelWithTitle,
enableFocusLossObservation,
disableFocusLossObservation,
Expand Down Expand Up @@ -120,36 +122,60 @@ describe( 'Sidebar', () => {
} );

it( 'should be possible to programmatically remove Document Settings panels', async () => {
await activatePlugin( 'gutenberg-test-plugin-post-formats-support' );

await createNewPost();
await enableFocusLossObservation();
await openDocumentSettingsSidebar();

expect( await findSidebarPanelWithTitle( 'Status' ) ).toBeDefined();
expect(
await findSidebarPanelWithTitle( 'Visibility:' )
).toBeDefined();
expect(
await findSidebarPanelWithTitle( 'Publish date:' )
).toBeDefined();
expect(
await findSidebarPanelWithTitle( 'Post Format' )
).toBeDefined();
expect( await findSidebarPanelWithTitle( 'Categories' ) ).toBeDefined();
expect( await findSidebarPanelWithTitle( 'Tags' ) ).toBeDefined();
expect(
await findSidebarPanelWithTitle( 'Featured image' )
).toBeDefined();
expect( await findSidebarPanelWithTitle( 'Excerpt' ) ).toBeDefined();
expect( await findSidebarPanelWithTitle( 'Discussion' ) ).toBeDefined();
expect(
await findSidebarPanelWithTitle( 'Status & visibility' )
).toBeDefined();

await page.evaluate( () => {
const { removeEditorPanel } = wp.data.dispatch( 'core/edit-post' );

removeEditorPanel( 'post-status' );
removeEditorPanel( 'visibility' );
removeEditorPanel( 'schedule' );
removeEditorPanel( 'post-format' );
removeEditorPanel( 'taxonomy-panel-category' );
removeEditorPanel( 'taxonomy-panel-post_tag' );
removeEditorPanel( 'featured-image' );
removeEditorPanel( 'post-excerpt' );
removeEditorPanel( 'discussion-panel' );
removeEditorPanel( 'post-status' );
} );

const getPanelToggleSelector = ( panelTitle ) => {
return `//div[contains(@class, "edit-post-sidebar")]//button[contains(@class, "components-panel__body-toggle") and contains(text(),"${ panelTitle }")]`;
};

expect( await page.$x( getPanelToggleSelector( 'Status' ) ) ).toEqual(
[]
);
expect(
await page.$x( getPanelToggleSelector( 'Visibility:' ) )
).toEqual( [] );
expect(
await page.$x( getPanelToggleSelector( 'Publish date:' ) )
).toEqual( [] );
expect(
await page.$x( getPanelToggleSelector( 'Post Format' ) )
).toEqual( [] );
expect(
await page.$x( getPanelToggleSelector( 'Categories' ) )
).toEqual( [] );
Expand All @@ -165,8 +191,7 @@ describe( 'Sidebar', () => {
expect(
await page.$x( getPanelToggleSelector( 'Discussion' ) )
).toEqual( [] );
expect(
await page.$x( getPanelToggleSelector( 'Status & visibility' ) )
).toEqual( [] );

await deactivatePlugin( 'gutenberg-test-plugin-post-formats-support' );
} );
} );
46 changes: 40 additions & 6 deletions packages/edit-post/src/components/sidebar/post-format/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,54 @@
/**
* WordPress dependencies
*/
import { PanelRow } from '@wordpress/components';
import { PanelBody } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import {
PostFormat as PostFormatForm,
PostFormatCheck,
} from '@wordpress/editor';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { store as editPostStore } from '../../../store';

const PANEL_NAME = 'post-format';

export default function PostFormat() {
const { isOpened, isRemoved } = useSelect( ( select ) => {
// We use isEditorPanelRemoved to hide the panel if it was
// programatically removed. We don't use isEditorPanelEnabled since
// this panel should not be disabled through the UI.
const { isEditorPanelRemoved, isEditorPanelOpened } = select(
editPostStore
);

return {
isOpened: isEditorPanelOpened( PANEL_NAME ),
isRemoved: isEditorPanelRemoved( PANEL_NAME ),
};
}, [] );

const { toggleEditorPanelOpened } = useDispatch( editPostStore );

if ( isRemoved ) {
return null;
}

export function PostFormat() {
return (
<PostFormatCheck>
<PanelRow>
<PanelBody
initialOpen={ false }
opened={ isOpened }
onToggle={ () => {
toggleEditorPanelOpened( PANEL_NAME );
} }
title={ __( 'Post Format' ) }
>
<PostFormatForm />
</PanelRow>
</PanelBody>
</PostFormatCheck>
);
}

export default PostFormat;
Loading