-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Cover: Customizing Alignment with Reakit Composite #21333
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
Cover: Customizing Alignment with Reakit Composite #21333
Conversation
|
Size Change: +361 B (0%) Total Size: 886 kB
ℹ️ View Unchanged
|
|
I cleaned up the code a little bit and fixed some issues I found, including the one you mentioned about it closing right away. Styles need some work and probably we will want to close the popover when the user clicks on an option? I'm not sure what was causing the problem, but I think it has something to do with this gutenberg/packages/components/src/higher-order/with-focus-outside/index.js Lines 67 to 90 in 963998e
When This sequence of blurring the container, focusing the item, blurring the item and focusing the container might be conflicting with the One option is to <Composite
onBlur={ ( event ) => {
if (
composite.items.some(
( item ) => item.ref.current === event.relatedTarget
)
) {
event.stopPropagation();
}
} }
/>But, it's safer to just use roving tabindex instead as this is a valid approach for grids. |
98692da to
b51794c
Compare
|
@diegohaz Wowow! Thank you so much! Your explanation makes sense. Beautiful refactors :D. Could not have done this without you 🤘 |
|
@diegohaz Haiii!! I made some refactors and pushed it up! One thing I'm noticing (that I'm not sure how to resolve, yet). I believe it touches upon the focus/blur logic you pointed out. This has to do with keyboard navigation when If we use Keyboard navigation (up, down, left, right), works as expected. But... Toolbar navigation is funky. When the AlignmentMatrix icon is focused, pressing If we use Keyboard navigation (up, down, left, right), does not work as expected. The movements are weird... However, Toolbar navigation works. 🤔 |
|
Collapsed I don't know if there's a gutenberg/packages/block-editor/src/components/block-switcher/index.js Lines 106 to 112 in 4b8d1f8
|
|
@diegohaz Thank you so much! That clue helped me a lot. I was able to fix it up. I had to swap Let's work on making these components seamless and better, together! 💪 |
a4ce5d5 to
22286b0
Compare
|
Yep! I’ll eventually need to update it to ToolbarButton later as part of the toolbar work I’m doing. 😅 |
|
@diegohaz You're the best <3 |
|
Nice team work 😍🔥 |
* WIP: Attempt to use Composite from Reakit * Fix issues and clean up composite code * Refactor Composite integration and update tests * Update snapshots * Fix keyboard navigation for AlignmentMatrixControl in Toolbar * Fix keyboard interaction to open Alignment position on keyboard down Co-authored-by: Haz <[email protected]>
* WIP: Attempt to use Composite from Reakit * Fix issues and clean up composite code * Refactor Composite integration and update tests * Update snapshots * Fix keyboard navigation for AlignmentMatrixControl in Toolbar * Fix keyboard interaction to open Alignment position on keyboard down Co-authored-by: Haz <[email protected]>
* WIP: Attempt to use Composite from Reakit * Fix issues and clean up composite code * Refactor Composite integration and update tests * Update snapshots * Fix keyboard navigation for AlignmentMatrixControl in Toolbar * Fix keyboard interaction to open Alignment position on keyboard down Co-authored-by: Haz <[email protected]>
* WIP: Attempt to use Composite from Reakit * Fix issues and clean up composite code * Refactor Composite integration and update tests * Update snapshots * Fix keyboard navigation for AlignmentMatrixControl in Toolbar * Fix keyboard interaction to open Alignment position on keyboard down Co-authored-by: Haz <[email protected]>
* WIP: Attempt to use Composite from Reakit * Fix issues and clean up composite code * Refactor Composite integration and update tests * Update snapshots * Fix keyboard navigation for AlignmentMatrixControl in Toolbar * Fix keyboard interaction to open Alignment position on keyboard down Co-authored-by: Haz <[email protected]>
* WIP: Attempt to use Composite from Reakit * Fix issues and clean up composite code * Refactor Composite integration and update tests * Update snapshots * Fix keyboard navigation for AlignmentMatrixControl in Toolbar * Fix keyboard interaction to open Alignment position on keyboard down Co-authored-by: Haz <[email protected]>
* Add initial AlignmentControl * Refactor AlignmentControl utils. Add basic tests for utils * Move AlignmentControl styled components to dedicated file * Add AlignControl icon. Refactor and share styles between main Control and Icon * Update Docs Manifest * Export AlignControl as __experimentalAlignControl * Fix export for AlignmentControl (__experimentalAlignmentControl) * Update packages/components/src/alignment-control/utils.js Co-Authored-By: Zebulan Stanphill <[email protected]> * Integrate AlignmentControl with Cover block Renamed AlignmentControl to AlignmentMatrixControl. * Update Docs manifest and Storyshot * Improve AlignmentMatrix rendering in Edit and Save functions Remove unused code from base AlignmentMatrix component * Prevent rendering of position className if undefined * Update Cover content position control label * Add padding to Cover (rather than inner content) * Adding a11y and RTL support to AlignmentMatrixControl Also refactors isRTL / useRTL from the rtl utils. * Add basic tests for keyboard movements * Cover: Customizing Alignment with Reakit Composite (#21333) * WIP: Attempt to use Composite from Reakit * Fix issues and clean up composite code * Refactor Composite integration and update tests * Update snapshots * Fix keyboard navigation for AlignmentMatrixControl in Toolbar * Fix keyboard interaction to open Alignment position on keyboard down Co-authored-by: Haz <[email protected]> * Update comments in AlignmentMatrixControl * Remove unnecessary fragment in Story * Refactor styles. Add knobs to AlignmentMatrixControl story * Adjust icon style * Add Tooltip to AlignmentMatrixControl cell * Remove onBlur handling and border styles * Account for center position * Adding code comment for width/height props in AlignmentMatrixControlIcon * Add prefix support in useInstanceId * Add code comment regarding icon export from AlignmentMatrixControl * Remove export of AlignmentMatrixControl icon element * Update stories + snapshot * Simplify nested array flattening * Remove padding from Cover editor.scss * Adjust BlockAlignmentMatrixToolbar popover className * Move padding styles to top of wp-block-cover selector * Fix AlignmentMatrixControl tests for window.focus in JSDOM * Replace Array.flat with lodash.flattenDeep Due to lack of polyfill support (at the moment). Co-authored-by: Zebulan Stanphill <[email protected]> Co-authored-by: Haz <[email protected]>

This PR attempts to implement the Composite component from Reakit into the new
AlignmentMatrixControl.For the initial integration attempt, it seemed to work as expected in Storybook (yay).
However, there appears to be issues within Gutenberg.
(Not) Playing Nicely with Toolbar
When expanding the Position dropdown in the Toolbar, the
AlignmentMatrixControlappears to have issues rendering (see below):It flashes and closes immediately. I'm not too sure why.
Seeing
unstable_virtual: falseseems to allow it to render okay. Although, the interactions and keyboard navigation seems to be off.CC'ing @diegohaz for expertise 😊
Thoughts/feedback welcome! We can change anything in this branch / draft PR