RichText component: Add label and/or help text attributes
What problem does this address?
It would be useful for the RichText component to have a label or help text attribute (or both!) to allow block developers to add text to the component to describe its intent within the block.
For example, if I were to create a block that would contain a person's profile information, that block would have attributes for the person's name and their bio. The bio would use the RichText component. It would be helpful to a content editor to see a label connected to that bio component, saying "Biography" or "Write a short bio about this person".
Right now, the only way to include any such description is with the placeholder text. This is not ideal for a couple of reasons:
- Placeholder text disappears when focus is on the input field.
- Placeholder text disappears when there is content in the input field.
- The first field of a block automatically gains focus when the block is added to the editor. If that field is a RichText component that has placeholder text, the content editor will not see the placeholder text unless they click out of that field. They may never see the placeholder text if they add that block and just start typing.
- Placeholder text is not necessarily read by all screen readers.
In case you want to read a ton of research about placeholders, the W3C has a page on placeholder research and accessibility
What is your proposed solution?
Please consider add a label and/or help text attribute to the RichText component, similar to what exists in the TextControl component.
What's the best HTML markup for something like this, @thatdevgirl?
@talldan Ideally, I would change it to something like this:
<label for="richtext-control-0">Label for my rich text field</label>
<div role="textbox" aria-multiline="true" id="richtext-control-0" aria-describedby="richtext-control-0__help"></div>
<p id="richtext-control-0__help">Here is some help text for this field</p>
This markup is inspired / largely copied from the markup used by the TextControl component. The <div role=textbox> is from the current Rich Text control.
The textbox has an ID that is used in the for attribute in the <label> tag above it.
The <p> tag below it contains the help text. Its ID is used in the aria-describedby attribute on the textbox div.