-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Table block: Fix focus loss after Create Table button is selected #40399
Changes from all commits
e5c36dc
3fb4f64
b09ea5a
e4455e0
b2af579
5ccae83
62e0e69
3430672
de235a9
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 |
---|---|---|
|
@@ -269,7 +269,6 @@ describe( 'Table', () => { | |
// Create the table. | ||
await clickButton( createButtonLabel ); | ||
|
||
await page.keyboard.press( 'Tab' ); | ||
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. This issue is fixed. 👍 |
||
await page.keyboard.type( '1' ); | ||
await page.keyboard.press( 'ArrowDown' ); | ||
await page.keyboard.type( '2' ); | ||
|
@@ -280,4 +279,18 @@ describe( 'Table', () => { | |
|
||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'should not have focus loss after creation', async () => { | ||
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. Added this test to ensure it doesn't break in the future. |
||
// Insert table block. | ||
await insertBlock( 'Table' ); | ||
|
||
// Create the table. | ||
await clickButton( createButtonLabel ); | ||
|
||
// Focus should be in first td. | ||
const isInTd = await page.waitForSelector( | ||
'td[contentEditable="true"]' | ||
); | ||
await expect( isInTd ).toHaveFocus(); | ||
} ); | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -678,27 +678,11 @@ describe( 'Writing Flow', () => { | |
await page.keyboard.press( 'Tab' ); | ||
// Create the table. | ||
await page.keyboard.press( 'Space' ); | ||
// Return focus after focus loss. This should be fixed. | ||
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. This was fixed. |
||
await page.keyboard.press( 'Tab' ); | ||
// Navigate to the second cell. | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await page.keyboard.type( '2' ); | ||
// Confirm correct setup. | ||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
// The content should only have one tab stop. | ||
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. This is not the case. Each Tab key press will land in a cell so removed this. Let me know if I should do anything differently. |
||
await page.keyboard.press( 'Tab' ); | ||
expect( | ||
await page.evaluate( () => | ||
document.activeElement.getAttribute( 'aria-label' ) | ||
) | ||
).toBe( 'Post' ); | ||
await pressKeyWithModifier( 'shift', 'Tab' ); | ||
await pressKeyWithModifier( 'shift', 'Tab' ); | ||
expect( | ||
await page.evaluate( () => | ||
document.activeElement.getAttribute( 'aria-label' ) | ||
) | ||
).toBe( 'Table' ); | ||
} ); | ||
|
||
it( 'Should unselect all blocks when hitting double escape', async () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am using the state to detect when table creation happens and then it fires the effect later. From my understanding, effects cannot listen for function execution but they can listen for states. If the state is set to true on creation, the effect will execute which will place focus in the table cell. After, it will set the state to false so it won't fire anymore. I set the ref as a property on the block so I had good targeting on my querySelector since that should be avoided.