Skip to content
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 editor heading for screenreaders #3937

Merged
merged 5 commits into from
Dec 22, 2017
Merged

Conversation

jasmussen
Copy link
Contributor

@jasmussen jasmussen commented Dec 12, 2017

This is round 2 of #3801.

It mitigates/fixes #503 and fixes #2024.

What remains to be done in this branch is:

  • Make sure the text is translatable, right now it's hardcoded to "Edit Post"
  • Make sure the text is contextual (so it shows Edit Page, Edit CPT etc)
  • Consider whether we show "Add New Post" on a fresh post, and change that to "Edit Post" when returning

This is round 2 of #3801.

It mitigates/fixes #503 and fixes #2024.

What remains to be done in this branch is:

- Make sure the text is translatable, right now it's hardcoded to "Edit Post"
- Make sure the text is contextual (so it shows Edit Page, Edit CPT etc)
@jasmussen jasmussen added [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Status] In Progress Tracking issues with work in progress labels Dec 12, 2017
@jasmussen jasmussen self-assigned this Dec 12, 2017
@jasmussen
Copy link
Contributor Author

@afercia in gutenberg.php, there's the following:

/**
 * Project.
 *
 * The main entry point for the Gutenberg editor. Renders the editor on the
 * wp-admin page for the plugin.
 *
 * @todo Remove the temporary fix for the NVDA screen reader and use meaningful
 *       content instead. See pull at and issues #467 and #503.
 *
 * @since 0.1.0
 */
function the_gutenberg_project() {
	?>
	<div class="nvda-temp-fix screen-reader-text">&nbsp;</div>
	<div class="gutenberg">
		<h1 class="screen-reader-text">Edit Post</h1>
		<div id="editor" class="gutenberg__editor"></div>
		<div id="metaboxes" style="display: none;">
			<?php the_gutenberg_metaboxes(); ?>
		</div>
	</div>
	<?php
}

Given that there's now a h1 inside the gutenberg div, should the nvda temp div be removed?

This just uses the stock WordPress objects.
@jasmussen
Copy link
Contributor Author

@gziolo in e682f1e I adopted/adapted some code to output a translated and contextual label for the heading. It seems to work well, insofar as it outputs "Edit Post" and "Edit Page" when it needs to. I haven't tested with custom post types, but I'm assuming since it taps into the same function, that it should work.

Can you help me with this? I need a sanity check my PHP, it's never been my forte. I'd also love some help testing with custom post types.

Finally, the $post_type_object->labels has entries for both Edit Post as well as Add New Post, but the logic to define when to output one vs. the other escapes me. Any advice here? Thanks a bunch.

gutenberg.php Outdated
@@ -27,9 +27,12 @@
* @since 0.1.0
*/
function the_gutenberg_project() {
global $post_type, $post_type_object;
$post_type_object = get_post_type_object( $post_type );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have much WP experience but it seems like $post_type_object might be null. I don't know if that will be caught in another place so we might provide fallback:

$screen_reader_text = ! empty( $post_type_object->labels->edit_item ) ? $post_type_object->labels->edit_item : __( 'Default text' );

It would make sense to double check with someone else. /cc @pento

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can assume that $post_type_object is set by the time the_gutenberg_project() is called.

For WordPress 4.9+:

  • For new posts, $post_type is sanity checked at the start of post-new.php, then $post_type_object is set. Later, the replace_editor filter is run, which calls gutenberg_init(), which may call the_gutenberg_project().
  • For existing posts, $post_type_object is set at the start of post.php, which bails before the replace_editor filter is run if $post_type_object is empty.

For <WordPress 4.9, gutenberg_intercept_edit_post() and gutenberg_intercept_post_new() simulate the same behaviour.

So, we don't need to include the $post_type_object = get_post_type_object( $post_type ); line, we can just access the $post_type_object global immediately.

@gziolo
Copy link
Member

gziolo commented Dec 12, 2017

I tested it with the page and post types. It works as advertised. Let's confirm PHP bits before we merge it.

@afercia
Copy link
Contributor

afercia commented Dec 12, 2017

Given that there's now a h1 inside the gutenberg div, should the nvda temp div be removed?

Yes! We can get rid of that ugly hack 🙂

Copy link
Member

@pento pento left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor change, everything else looks good.

gutenberg.php Outdated
@@ -27,9 +27,12 @@
* @since 0.1.0
*/
function the_gutenberg_project() {
global $post_type, $post_type_object;
$post_type_object = get_post_type_object( $post_type );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can assume that $post_type_object is set by the time the_gutenberg_project() is called.

For WordPress 4.9+:

  • For new posts, $post_type is sanity checked at the start of post-new.php, then $post_type_object is set. Later, the replace_editor filter is run, which calls gutenberg_init(), which may call the_gutenberg_project().
  • For existing posts, $post_type_object is set at the start of post.php, which bails before the replace_editor filter is run if $post_type_object is empty.

For <WordPress 4.9, gutenberg_intercept_edit_post() and gutenberg_intercept_post_new() simulate the same behaviour.

So, we don't need to include the $post_type_object = get_post_type_object( $post_type ); line, we can just access the $post_type_object global immediately.

@jasmussen
Copy link
Contributor Author

Thanks a bunch for the review! I pushed the change.

If the change was correctly interpreted, and this is good to merge, feel free to do so. I'm heading out for some holiday today! ❤️

gutenberg.php Outdated
@@ -25,7 +25,6 @@
*/
function the_gutenberg_project() {
global $post_type, $post_type_object;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasmussen you don't need $post_type in here. Otherwise is all good to go :)

@gziolo
Copy link
Member

gziolo commented Dec 22, 2017

I will give it a spin and merge today :)

Copy link
Member

@pento pento left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 after the change @gziolo mentioned.

@gziolo gziolo merged commit f023754 into master Dec 22, 2017
@gziolo gziolo deleted the try/edit-heading-round-2 branch December 22, 2017 12:05
@@ -110,7 +110,7 @@ class PostTitle extends Component {
tabIndex={ -1 /* Necessary for Firefox to include relatedTarget in blur event */ }
>
{ isSelected && <PostPermalink /> }
<h1>
<div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasmussen was this div needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was needed in order to let this "pseudo" block inherit styles that look exactly like our other blocks, without writing completely different CSS.

I did try to apply the on-select border to the textarea itself, or pseudo selectors, but it added a ton of complexity to the CSS, and I don't think I was able to get the responsive behavior to be the same. I decided it wasn't worth a complete rewrite to save this div, and I'm still unconvinced it can be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Status] In Progress Tracking issues with work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Heading hierarchy in the sidebar Add headings for the Editor screen main sections
5 participants