-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Show block anchor attribute in Block Navigation #16898
Conversation
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.
@@ -46,6 +46,7 @@ function BlockNavigationList( { | |||
> | |||
<BlockIcon icon={ blockType.icon } showColors /> | |||
{ blockType.title } | |||
{ block.attributes.anchor && <span className="block-editor-block-navigation__item-anchor-name">{ block.attributes.anchor }</span> } |
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.
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 confirm that this implementation assumes a bit too much about the name of attribute. Enforcing that this attribute can’t be used for anything else might be too cumbersome. We should at least ensure that anchor is one the flag in the supports object defined for the block.
By the way, I know that the mobile part of project experiments with an API which creates a version of the block description which is used for accessibility purposes. It clearly shows that title and description are too generic when we have multiple instances of the same block in one document. We should seek to find a way to make it possible to offer more flexibility on how blocks can be described/announced depending on the context.
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 have refactored the code to check if the block supports the "anchor" feature.
Thanks for this, great to see it move into a PR. I think having it change color as in original screenshot by @mtias would be great: |
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 "anchor" support is written as a hook, so technically speaking the "block-editor" package has no way to know that this hook exists or not.
That said, I feel like there's a middle ground here between being completely generic (having a block API for this) or being very specific and that's what this PR is achieving.
I think I wouldn't mind trying it like that, but I'd love thoughts from the team @mtias @mcsf
This is exactly what I shared in the 2nd part of my #16898 (comment). I didn't think about the fact that this is something that the block editor should be aware of. In the long run, we should provide some formal API which will allow rendering some sort of previews of the block depending on the context: visual, text-based, screen-reader optimized. At the same time, I wonder how friendly those anchors will be for screen-reader users? |
An API such as that devised by the mobile team could, in this case, be used directly by the anchor hook implementation, provided that BlockNavigation is extensible.
This is good to think about, but I wouldn't block this PR based on it. Maybe it serves as some consolation that the anchor hook lives in the
In my mind there's two ways to look at the problem: enhanced previewing methods, as you suggest, and better systematic extraction of the relevant content in a block.
|
409f2e8
to
f76b629
Compare
To evaluate this from a design perspective, it may help to take a few steps back and determine what problem are we trying to solve? by adding this functionality. It's not immediately clear from #16307 what the core user problem that we're solving for is, but there may be some missing context there. My guess is that the purpose here is one or both of: Working backwards, I looked for a way to set an anchor or an ID in the interface itself, but could only find a way of adding classes (without resorting to the HTML editor, that is.) Is the anchor or ID attribute something that users add themselves or are they added programmatically? If the references are user-defined, they're a potentially useful tool in helping users navigate through a document. This certainly seems like the idea scenario, but I'm struggling to figure out how a user might be able to define an anchor like this... which likely means that most users won't know how to define an anchor, either. If they're added programmatically, they may not have as much value to the majority of users, who likely won't know what they mean or how to use them. In this case, we run the risk of adding noise to the interface without providing real value. |
@sarahmonster you can add anchors under I've only ever used this to mark up headings so I could link directly to that section of a page. I've never thought about using it for adding context (as I've never written anything as complex in an editor that supported anchors) but now that you mention it, that might a use case - though it does feel a bit like an edge case yeah. If I were to say what I'd use this for, it's to link to specific headings when sharing the URL to my page. So then the most important part for me is to be able to copy that link. The blue color suggested above would indicate that the anchor is clickable, if that then copies the permalink+anchor to my clipboard that would be useful. As for the location and design, that seems to be in the right place, looks good. I wonder if maybe we could mitigate the length issue by increasing the margins of the items and bit and then placing the anchor below the block name label. |
What should we do with this PR? |
Closing as this was implemented in #31992. |
Description
Added showing the block anchor ID in the block navigation.
Long anchor IDs is a potential issue that's up for discussion. At the moment I've hidden the overflow.
Fixes #16307.
How has this been tested?
Developed and tested within the provided dockerized Wordpress.
Screenshots
Checklist: