-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add @wordpress/a11y script module #7405
Conversation
c6fcf75
to
6e814fb
Compare
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
8f38434
to
d6201e3
Compare
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 Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
/** | ||
* Tracks wehther the @wordpress/a11y script module is available. | ||
* | ||
* Some additional HTML is required on the page for the module to work. Track | ||
* whether it's available to print at the appropriate time. | ||
* | ||
* @since 6.7.0 | ||
* @var bool | ||
*/ | ||
private $a11y_available = false; |
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 don't love this, but as a private property I'm not too worried. I wanted to avoid iterating over the enqueued modules and the dependency graph repeatedly and this property allowed for pre-existing iteration to be used.
Perhaps when https://core.trac.wordpress.org/ticket/60597 is addressed a method like ::is_available( '@wordpress/a11y' )
could be implemented to know whether the module will be "available" (enqueued or in the import map).
@gziolo @DAreRodz @michalczaplinski this is ready for review. It can't be tested with #7304 at this time unless |
This code is needed for compatibility with WordPress < 6.7. The filter should only be registered if the Core filter will not run, otherwise redundant elements are printed. See: WordPress/wordpress-develop#7405
Co-authored-by: Michal <mmczaplinski@gmail.com>
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 looks good to me! 👍
I've also tested it with a simple custom block using the @wordpress/a11y
module:
view.js
of my custom block
import { store, getContext } from "@wordpress/interactivity";
store("create-block", {
actions: {
toggle: () => {
const context = getContext();
context.isOpen = !context.isOpen;
},
},
callbacks: {
logIsOpen: function* () {
const { isOpen } = getContext();
const { speak } = yield import("@wordpress/a11y");
console.log("isOpen", isOpen);
if (isOpen) {
speak("toggle open", "assertive");
} else {
speak("toggle closed", "assertive");
}
},
},
});
output_2278ef.mp4
Committed via https://core.trac.wordpress.org/changeset/59089 |
This code is needed for compatibility with WordPress < 6.7. The filter should only be registered if the Core filter will not run, otherwise redundant elements are printed. See: WordPress/wordpress-develop#7405
Add a new
@wordpress/a11y
Script Module. The Script Module has the same API as thewp-a11y
WP Script.This implements Gutenberg PRs WordPress/gutenberg#65101 and WordPress/gutenberg#65380 to add the
@wordpress/a11y
Script Module in Core.One difference with the
wp-a11y
WP Script is that the necessary HTML is injected into the initial page's HTML. The Script injects some elements into the DOM when loaded. This is problematic with accessibility live regions and modules that may have deferred loading. The background and justification for this change was discussed in WordPress/gutenberg#65380.The script and module do not conflict. If the script is loaded, it will not inject elements into the DOM but will re-use the HTML rendered for the module. There is some potential for conflict if the live regions are used simultaneously by the script and module, but this has always been the case if different consumers use the script simultaneously.
#7304 and WordPress/gutenberg#65539 leverage the new
@wordpress/a11y
Script Module in the@wordpress/interactivity-router
script module.Testing
This can be tested by adding a dependency on
@wordpress/a11y
from another script module. The exposedspeak
function should work when the module is imported dynamically or statically.If the
wp-a11y
script is also enqueued, no duplicate live regions should be injected into the DOM. Both the script's and the module'sspeak
function should work correctly.It can be helpful to observe a something like this in the browser console:
For example:
Trac ticket: https://core.trac.wordpress.org/ticket/60647
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.