-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: Add toolbar button to add a caption #47984
Conversation
// Click the first cell and add some text. | ||
await page.click( 'role=document[name="Block: Table"i] >> figcaption' ); | ||
await editor.clickBlockToolbarButton( 'Add caption' ); | ||
const caption = page.locator( | ||
'role=textbox[name="Table caption text"i]' | ||
); | ||
await expect( caption ).toBeFocused(); |
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.
The purpose of this change is the same as for the gallery block.
Please see: #47325 (comment)
Flaky tests detected in baab6f2. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9643501188
|
Size Change: -71 B (0%) Total Size: 1.76 MB
ℹ️ View Unchanged
|
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.
This seems like a complex interactions regarding undo/redo and state synchronization, do we want to add more e2e tests about this?
const captionRef = useCallback( | ||
( node ) => { | ||
if ( node && ! caption ) { | ||
node.focus(); |
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 think there's an a11y bug where undo/redo-ing from an empty caption to some content in the caption will move the focus to the caption <RichText>
. This might not be ideal when the focus is previously on the undo/redo button, for instance. @alexstine knows more about this than me.
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.
Good point. If I'm not wrong, it seems to me this happens also on the table cells. Happens also on other blocks, e.g. a paragraph, when undoing form an empty paragraph to some previous content in teh paragraph.
The focus 'jump' is a big problem, as it's totally unexpected. Could you please confirm it happens also in other blocks? 🙏 If so, I'd think a separate issue to solve the problem more holistically would be best.
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 may not know exactly what the problem is, but is it a case of, for example, the following? In both cases, I can confirm that the focus jumps.
In the table block, undoing typed text shifts focus to the caption.
f3ebbe7b158cadfcb736bd7c943ae54d.mp4
Undoing on the first deleted paragraph brings the focus to the second paragraph
f3ebbe7b158cadfcb736bd7c943ae54d.mp4
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.
Oops! Sorry for the confusion. I meant the undo/redo "buttons" in the toolbar rather than the shortcuts. See the below screencast for example:
Kapture.2023-02-21.at.14.05.52.mp4
You can see that after triggering the undo/redo buttons, the focus moves from the buttons to the caption input.
// We need to show the caption when changes come from | ||
// history navigation(undo/redo). | ||
useEffect( () => { | ||
if ( caption && ! prevCaption ) { | ||
setShowCaption( true ); | ||
} | ||
}, [ caption, prevCaption ] ); | ||
|
||
useEffect( () => { | ||
if ( ! isSelected && ! caption ) { | ||
setShowCaption( false ); | ||
} | ||
}, [ isSelected, caption ] ); |
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'm not sure if syncing states via useEffect
here is the best option. We might be able to achieve the same thing by deriving some of them here.
For instance, we could create a state isCaptionToggled
and a derived state showCaption
like this:
const [ isCaptionToggled, setIsCaptionToggled ] = useState( !! caption );
const showCaption = !! caption || ( isCaptionToggled && isSelected );
Not sure if it will work though, needs more testing 😅 .
Thanks @t-hamano ❤️ However, it's worth reminding that the figure/figcaption elements for the Table block are under ongoing discussion since a while. Semantically, the Cc @joedolson |
c4fec03
to
da1a333
Compare
Update: Sorry for the delay in checking this PR. I learned that a reusable caption component was added in #56606. Therefore, I have updated this PR to use this component as well. This component is hardcoded to be rendered as a |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@t-hamano I tested the accessibility as well and it works fine in the current version 👍 |
@t-hamano, do you mind rebasing one more time? That should also unblock current CI checks. |
@Mamaduka I've updated this PR 👍 |
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.
Thanks, @t-hamano!
Thanks everyone for the reviews! I tested this PR again just to be sure, and it works as expected, so I'll merge it. |
* Use Caption component * Fix e2e test Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: kevin940726 <kevin940726@git.wordpress.org> Co-authored-by: afercia <afercia@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: BenjaminZekavica <benjamin_zekavica@git.wordpress.org>
Related to:
What?
This PR adds a toggle toolbar item on the table block toolbar to add/remove a caption.
How?
The approach is the same as the other PRs, but I had a little trouble with the order of the caption buttons.Update: I learned that a reusable caption component was added in #56606. Therefore, I have updated this PR to using this component as well.
Testing Instructions