Skip to content

Should anchor hook automatically format attribute text? #25304

Closed

Description

@mkaz

In #23197 anchor tag support was adding using hooks, this allows adding a supports: { anchor: true } property on a block that enables a field in advanced that can be set. Additionally a block can use setAttrtbiutes: { anchor: "Anchor text" } and it will set the value for the anchor field.

However, the value does not automatically get converted to a valid value, per the spec, it should contain no whitespace.

When specified on HTML elements, the id attribute value must be unique amongst all the IDs in the element's tree and must contain at least one character. The value must not contain any ASCII whitespace.
From: https://html.spec.whatwg.org/multipage/dom.html#the-id-attribute

Question: should the anchor hook automatically format the values being set?

My thought is yes, and also lower-case, switch whitespace to "-" so something like "Anchor text" would become "anchor-text"

We could then resolve #6182 by updating the onChange: setAttributes( { content: value, anchor: value } )

Granted there is an issue for non-unique ids on the page, but that exists now regardless of heading.

Thoughts?

Activity

  1. added
    Needs Technical Feedback
    [Package] Block editor
    on Sep 14, 2020
  2. added
    [Feature] Block API
    [Type] Enhancement
    and removed
    Needs Technical Feedback
    on Sep 15, 2020
  3. youknowriad commented on Sep 15, 2020

    @youknowriad
    Contributor

    it makes sense to me. For #6182 we might be able to loop over blocks and detect duplicates.

  4. skorasaurus commented on Nov 8, 2021

    @skorasaurus
    Member

    @mkaz can this now be closed since it's been decided upon and used in #30825 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Block API[Package] Block editor[Type] Enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions