-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Details Block: Fix keyboard accessibility issues and allow list view selection to show up inner blocks #70056
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
Changes from all commits
b84e51e
b324957
7c9b0f8
6e93dc7
6e496b3
a7464e9
60e3607
8d9a80f
66646d5
181a8ae
51ee2b9
adac974
e51bae0
ade7309
25820e1
4dc9cf0
f3d5d6b
0b2c3af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { ComponentsContext } from './context/context-system-provider'; | |
| import Theme from './theme'; | ||
| import { Tabs } from './tabs'; | ||
| import { kebabCase, normalizeTextString } from './utils/strings'; | ||
| import { withIgnoreIMEEvents } from './utils/with-ignore-ime-events'; | ||
| import { lock } from './lock-unlock'; | ||
| import Badge from './badge'; | ||
|
|
||
|
|
@@ -18,6 +19,7 @@ lock( privateApis, { | |
| Theme, | ||
| Menu, | ||
| kebabCase, | ||
| withIgnoreIMEEvents, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @WordPress/gutenberg-components We export this HOF as a private API. We need this function in the block library to prevent the Details content from being toggled by the Enter key event fired by the IME event.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update: Let's test whether it works without this HOF.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update: If the HOF is not used, unintended events occur in the IME and it does not work properly (See #70056 (comment)). Therefore, it is necessary to use HOF as a private API. |
||
| Badge, | ||
| normalizeTextString, | ||
| } ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
|
||
| test.describe( 'Details', () => { | ||
| test.beforeEach( async ( { admin } ) => { | ||
| await admin.createNewPost(); | ||
| } ); | ||
|
|
||
| test( 'can toggle hidden blocks by pressing enter', async ( { | ||
| editor, | ||
| page, | ||
| } ) => { | ||
| // Insert a details block with empty inner blocks. | ||
| await editor.insertBlock( { | ||
| name: 'core/details', | ||
| attributes: { | ||
| summary: 'Details summary', | ||
| }, | ||
| innerBlocks: [ | ||
| { | ||
| name: 'core/paragraph', | ||
| attributes: { | ||
| content: 'Details content', | ||
| }, | ||
| }, | ||
| ], | ||
| } ); | ||
|
|
||
| // Open the details block. | ||
| await page.keyboard.press( 'Enter' ); | ||
|
|
||
| // The inner block should be visible. | ||
| await expect( | ||
| editor.canvas.getByRole( 'document', { name: 'Block: Paragraph' } ) | ||
| ).toContainText( 'Details content' ); | ||
|
|
||
| // Close the details block. | ||
| await page.keyboard.press( 'Enter' ); | ||
|
|
||
| // The inner block should be hidden. | ||
| await expect( | ||
| editor.canvas.getByRole( 'document', { name: 'Block: Paragraph' } ) | ||
| ).toBeHidden(); | ||
| } ); | ||
|
|
||
| test( 'can create a multiline summary with Shift+Enter', async ( { | ||
| editor, | ||
| page, | ||
| } ) => { | ||
| // Insert a details block. | ||
| await editor.insertBlock( { | ||
| name: 'core/details', | ||
| } ); | ||
|
|
||
| const summary = editor.canvas.getByRole( 'textbox', { | ||
| name: 'Write summary', | ||
| } ); | ||
|
|
||
| // Add a multiline summary. | ||
| await summary.type( 'First line' ); | ||
| await page.keyboard.press( 'Shift+Enter' ); | ||
| await summary.type( 'Second line' ); | ||
|
|
||
| // Verify the summary is multiline. | ||
| await expect( summary ).toHaveText( 'First line\nSecond line', { | ||
| useInnerText: true, | ||
| } ); | ||
| } ); | ||
|
|
||
| test( 'typing space in summary rich-text should not toggle details', async ( { | ||
| editor, | ||
| } ) => { | ||
t-hamano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Insert a details block. | ||
| await editor.insertBlock( { | ||
| name: 'core/details', | ||
| } ); | ||
|
|
||
| const summary = editor.canvas.getByRole( 'textbox', { | ||
| name: 'Write summary', | ||
| } ); | ||
|
|
||
| // Type space in the summary rich-text. | ||
| await summary.type( ' ' ); | ||
|
|
||
| // Verify the details block is not toggled. | ||
| await expect( | ||
| editor.canvas.getByRole( 'document', { name: 'Empty block' } ) | ||
| ).toBeHidden(); | ||
| } ); | ||
|
|
||
| test( 'selecting hidden blocks in list view expands details and focuses content', async ( { | ||
| editor, | ||
| page, | ||
| pageUtils, | ||
| } ) => { | ||
| // Insert a details block. | ||
| await editor.insertBlock( { | ||
| name: 'core/details', | ||
| attributes: { | ||
| summary: 'Details summary', | ||
| }, | ||
| innerBlocks: [ | ||
| { | ||
| name: 'core/paragraph', | ||
| attributes: { | ||
| content: 'Details content', | ||
| }, | ||
| }, | ||
| ], | ||
| } ); | ||
|
|
||
| const listView = page.getByRole( 'treegrid', { | ||
| name: 'Block navigation structure', | ||
| } ); | ||
|
|
||
| // Open the list view. | ||
| await pageUtils.pressKeys( 'access+o' ); | ||
|
|
||
| // Verify inner blocks appear in the list view. | ||
| await page.keyboard.press( 'ArrowRight' ); | ||
| await expect( | ||
| listView.getByRole( 'link', { | ||
| name: 'Paragraph', | ||
| } ) | ||
| ).toBeVisible(); | ||
|
|
||
| // Verify the first inner block in the list view is focused. | ||
| await page.keyboard.press( 'ArrowDown' ); | ||
| await expect( | ||
| listView.getByRole( 'link', { | ||
| name: 'Paragraph', | ||
| } ) | ||
| ).toBeFocused(); | ||
|
|
||
| // Verify the first inner block in the editor canvas is focused. | ||
| await page.keyboard.press( 'Enter' ); | ||
| await expect( | ||
| editor.canvas.getByRole( 'document', { name: 'Block: Paragraph' } ) | ||
| ).toBeFocused(); | ||
| } ); | ||
| } ); | ||
Uh oh!
There was an error while loading. Please reload this page.