Problem/Motivation

Block titles can currently be displayed or hidden by site-builders. When hidden, the heading element is omitted from the HTML entirely. Hiding titles might be desirable for a visual design, however block titles can be useful for visually impaired users, providing contextual clarity and navigational cues via screenreaders.

Proposed resolution

Add another option in block configuration, to output visually-hidden block titles, with a "visually-hidden" class.
In D7 this functionality is provided by the a11y_titles module.

We have already added equivalent functionality to D8 for the FieldAPI label display. Offering visually-hidden block titles will extend the options available for site builders to fine-tune the page structure.

Before

After

Remaining tasks

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Create a patch Instructions Done
Reroll the patch if it no longer applies. Instructions Done
Add automated tests Instructions Done
Update the patch to incorporate feedback from reviews (include an interdiff) Instructions Done
Manually test the patch Novice Instructions Done
Embed before and after screenshots in the issue summary Novice Instructions Done
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards Instructions
  • Usability review: this accomodates an additional option by replacing a checkbox with a select element, similar to the label display for field formatters.
  • Documentation: explain the visually-hidden option on the block help page?
  • Update settings form in \Drupal\Core\Block\BlockBase::buildConfigurationForm()
  • Update HTML output in block module, adding "visually-hidden" class to title_attribute twig variable via template_preprocess_block. The block twig template does not need to be changed.
  • Update block settings config schema. Not necessary - block_settings.label_display is already type: string, not boolean.
  • Update installation config in core profiles/modules, changing block_settings.label_display values of '0' to explicit 'hidden'. It would be a BC break so keep the '0' value for hidden titles.
  • hook_update(). Change block_settings.label_display values of '0' to explicit 'hidden'. Not usefull anymore (see previous)
  • Write tests.
  • Some blocks have custom behaviour, e.g. menu blocks already have visually hidden titles, and Bartik uses it's own CSS to hide block titles in the header region. Come up with an approach for these - we might be able to remove custom templates and CSS, relying instead on installation config. Should be done in follow-up issues.

User interface changes

Block title display option changes from a boolean checkbox option to 3 options in a select element: Visible, Visually Hidden, Hidden.
Aim for consistency with the Field API options in entity manage-display settings.

Also descriptive help text may change (D7 a11y_titles module says "Block titles can provide context to users who can’t rely on visual cues").

API changes

None expected.

Data model changes

We are introducing a third option to Block title display: 'visually-hidden'. Effect on data model are as follows:

  • Config Schema: NO CHANGE. While we are introducing an additional option ('visually-hidden') for the core data type block_settings.label_display, this is already of type: string, which accommodates all proposed values (visible, visually-hidden, hidden).
  • Installation Config: CHANGED. Block configuration files in config/install folders will need to be updated, changing block_settings.label_display values of '0' to explicit 'hidden'. Removed for BC
  • Existing Sites' Config: UPDATE HOOK required, changing block_settings.label_display values of '0' to explicit 'hidden'. Removed for BC
CommentFileSizeAuthor
#139 23_01_8596_D11.patch30.22 KBdhavalpanchal
#137 2614950-nr-bot_d634nn56.txt6.16 KBneeds-review-queue-bot
#134 2614950-nr-bot_zu0vc0al.txt90 bytesneeds-review-queue-bot
#132 core-2614950-132.patch16.86 KBguietc
#131 2614950-nr-bot.txt6.15 KBneeds-review-queue-bot
#127 core-2614950-127.patch13.38 KBfskreuz
#126 core-2614950-126.patch13.6 KBfskreuz
#125 core-visually_hidden_block_title_option-2614950-125.patch13.61 KBfskreuz
#122 core-visually_hidden_block_title_option-2614950-122.patch13.48 KBfskreuz
#118 interdiff_117-118.txt3.28 KBpradhumanjain2311
#118 2614950-118.patch17.57 KBpradhumanjain2311
#117 reroll_diff_115-117.txt9.79 KBsahil.goyal
#117 2614950-117.patch17.66 KBsahil.goyal
#115 do-core-visually-hidden-block-titles-2614950-114.patch17.69 KBidiaz.roncero
#112 do-core-visually-hidden-block-titles-2614950-112.patch17.71 KBlouisnagtegaal
#109 visually-hidden-block-titles-2614950-109.patch18.31 KBsutharsan
#107 visually-hidden-block-titles-2614950-107.patch17.87 KBBarisW
#106 2614950-106.patch38.3 KBnikitagupta
#102 Screenshot from 2020-11-12 09-24-02.png61.28 KBbarone
#102 Screenshot from 2020-11-12 09-23-15.png63.66 KBbarone
#102 Screenshot from 2020-11-12 09-23-07.png36.99 KBbarone
#101 interdiff_96-101.txt1.16 KBraman.b
#101 2614950-101.patch38.38 KBraman.b
#97 2614950-after_patch-96_2.png86.66 KBabhijith s
#97 2614950-after_patch-96_1.png38.4 KBabhijith s
#96 interdiff_93-96.txt19.92 KBraman.b
#96 2614950-96.patch38.29 KBraman.b
#93 reroll-2614950-93.patch17.91 KBjaykandari
#89 visually-hidden-block-titles-2614950-88.patch12.89 KBkishor_kolekar
visually-hidden-block-titles-2614950-88.patch12.89 KBkishor_kolekar
visually-hidden-block-titles-2614950-88.patch12.89 KBkishor_kolekar
#80 block-heading-render-issues.jpg44.8 KBedmonkey
#78 visually-hidden-block-titles-2614950-78.patch18.13 KBduaelfr
#74 visually-hidden-block-titles-2614950-74.patch101.52 KBduaelfr
#74 interdiff.2614950.72.74.txt2.03 KBduaelfr
#72 visually-hidden-block-titles-2614950-72.patch15.47 KBduaelfr
#70 2614950-69.patch15.44 KBnaveenvalecha
#65 2614950-50.patch15.36 KBnaveenvalecha
#64 2904915-50.patch79.3 KBnaveenvalecha
#62 visually-hidden-block-titles-2614950-62.patch14 KBduaelfr
#62 interdiff.2614950-62.2785047.txt3.46 KBduaelfr
#55 visually-hidden-block-titles-2614950-55.patch12.58 KBduaelfr
#47 visually-hide-2.gif564.25 KByoroy
#46 visually-hide-options.gif54.32 KByoroy
#32 2614950_POST_PATCH_2.png120.9 KBagomezmoron
#32 2614950_POST_PATCH_1.png15.85 KBagomezmoron
#32 2614950_PRE_PATCH_2.png5.93 KBagomezmoron
#32 2614950_PRE_PATCH_1.png11.57 KBagomezmoron
#30 visually-hidden-block-titles-2614950-30.patch12.47 KBduaelfr
#29 visually-hidden-block-titles-2614950-29.patch15.48 KBduaelfr
#29 interdiff.2614950.27.29.txt2.69 KBduaelfr
#27 visually-hidden-block-titles-2614950-27.patch13.17 KBduaelfr
#27 interdiff.2614950.24.27.txt7.02 KBduaelfr
#24 visually-hidden-block-titles-2614950-24.patch4.4 KBduaelfr
#24 interdiff.2614950.22.24.txt4.17 KBduaelfr
#8 visually-hidden-block-titles-2614950-8.patch3.87 KBandrewmacpherson
#20 visually-hidden-block-titles-2614950-20.patch3.84 KBduaelfr
#22 interdiff.2614950.20.22.txt5.43 KBduaelfr
#22 visually-hidden-block-titles-2614950-22.patch7.78 KBduaelfr

Issue fork drupal-2614950

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

andrewmacpherson created an issue. See original summary.

andrewmacpherson’s picture

Issue summary: View changes
mgifford’s picture

This would be a great addition to Core!

andrewmacpherson’s picture

Issue summary: View changes

I dug into the settings form and config schema, and it looks like we won't need to update the schema at all, since block_settings.label_display is already a string. (I had assumed it would be a boolean).

We'll be adding a new option 'hidden', but the schema already copes with this I think. label_settings will either have value 'visible' or '0' in existing D8.0.x installations. I don't think there's a need to mess with this for upgrading sites.

Updated the issue summary to reflect this, crossed 2 tasks off the list.

andrewmacpherson’s picture

Issue summary: View changes

Hmm, I spoke too soon. The '0' value needs changing to an explicit 'hidden'. Currently it only stores a '0' because it's a checkbox, with no explicit value for unchecked. Once we're on three options, they'll all need explicit values, regardless of whether we use a select or radio buttons. I propose 'visible', 'visually-hidden', and 'hidden' as the values.

it still doesn't require a schema change, but does need changes to installation config, and an update hook.

Updating issue summary.

andrewmacpherson’s picture

Issue summary: View changes

The "Display title" form element is in \Drupal\Core\Block\BlockBase::buildConfigurationForm().

The current setting comes from a constant - BlockInterface::BLOCK_LABEL_VISIBLE, so that's another thing to change, maybe add a couple more constants for hidden and visually-hidden, and use these for the #options in the form element. Let's check how field label options are handled, for consistency.

Updating issue summary.

andrewmacpherson’s picture

Issue summary: View changes

The block module implements hook_help(). We might want to update that with an explanation of the visually-hidden setting. (I looked at the help page for field_ui, but the label visibility settings aren't explained there.)

andrewmacpherson’s picture

Issue summary: View changes
StatusFileSize
new3.87 KB

This patch does the following:

  • Adds a couple of constants to BlockInterface to represent the hidden and visually-hidden options.
  • Updates the Block configuration form, replacing a title display checkbox with a select element.
  • Adds a helper function to get the the options for the select element.
  • Updates block_preprocess to add a visually-hidden class where needed.

This patch will likely fail, as tests haven't been changed yet.

Don't be alarmed if you see lots of block titles in the seven admin theme - still need to update install config and provide an update hook.

andrewmacpherson’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: visually-hidden-block-titles-2614950-8.patch, failed testing.

Jeff Burnz’s picture

andrewmacpherson’s picture

Issue summary: View changes

Thanks Jeff. I'd discovered that some block titles had special behaviour/styles in core themes, such as menu blocks already having visually hidden titles. We should come up with an approach for these - it would be cool is we can remove some custom templates and CSS, relying instead on installation config.

I've added an extra task to the issue summary for this, and we can note specific examples as we find them.

The patch in #2625834: Make the visibility of block titles in the header optional. contains an example of an update hook to change all the existing block settings too, handy.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dcrocks’s picture

In a sense a ternary version of the label_dispaly variable is implemented in the block twig.html files. Currently the status of 'label_display' is tested 2 ways in drupal twig templates. These are 8 templates that use {% if label %}. These are relying on "template_preprocess_block" to actually test the config setting of label_display and simply skip rendering of the title if it is empty. 3 menu twig template files use {% if not configuration.label_display %} and add the "visually-hidden" class to the title element if it is not set.
It seems to me any one can have local copies of block templates and make their own decisions about how to handle the label. The existing block templates actually do show the 3 possible options identified in this issue, ie. the block label can be omitted, visually hidden, or visible.
I do think some existing blocks should be reviewed(eg. site branding block) as to whether they should omit the label or visually hide it, for ada conformance.

dcrocks’s picture

I created a new issue that I think is relevant to this one, #2715687: make templates use 'display_label' in consistent manner. I am hoping to spur discussion there that could affect the eventual result of this issue.

mgifford’s picture

Issue tags: +atag

This would give more control to the users editors.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Related issue fixed, so new constants should live inside plugin interface #2829680: BLOCK_LABEL_VISIBLE is defined on the wrong interface

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

duaelfr’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
StatusFileSize
new3.84 KB

Patch rerolled against 8.4.x including changes from #18
It still needs the tests to be fixed and new tests to be added, though.

Status: Needs review » Needs work

The last submitted patch, 20: visually-hidden-block-titles-2614950-20.patch, failed testing.

duaelfr’s picture

Status: Needs work » Needs review
StatusFileSize
new7.78 KB
new5.43 KB

I added an upgrade path and fixed core templates that used the old way to hide block title.
I'm afraid we should use a "0" value instead of the "hidden" we introduced in this patch to preserve BC. It's up to discussion.
We still need tests here, though.

The last submitted patch, 22: visually-hidden-block-titles-2614950-22.patch, failed testing.

duaelfr’s picture

StatusFileSize
new4.17 KB
new4.4 KB

I discussed about it offline at dev days Seville with Artusamak and we thought it was possible to introduce that new option without breaking BC.
Here is a patch that removes BC breaks from the previous one by reverting the \Drupal\Core\Block\BlockPluginInterface::BLOCK_LABEL_HIDDEN value to "0", which is it's current value, and reverting the code that were changed in templates to make it work when it was "hidden".

Next step is to fix the existing tests, then write new ones.

Status: Needs review » Needs work

The last submitted patch, 24: visually-hidden-block-titles-2614950-24.patch, failed testing.

duaelfr’s picture

Assigned: Unassigned » duaelfr

I'm still working on this one.

duaelfr’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new7.02 KB
new13.17 KB

Tests should be fixed and completed.
Give me a green, dear testbot!

---
I had to fix an existing test (\Drupal\block\Tests\BlockTest::testHideBlockTitle) that were doing strange things.
In fact, that test was testing that the block title was not shown by default. But, given the existing UI, the block title IS shown by default. That's just because of the internal \Drupal\simpletest\WebTestBase::drupalPostForm() mecanisms that mess with checkboxes that the tests didn't fail right now (not sending a value is like sending an unchecked checkbox, which is different from its default value). It would have failed when converted to BrowserTestBase anyway.

Status: Needs review » Needs work

The last submitted patch, 27: visually-hidden-block-titles-2614950-27.patch, failed testing.

duaelfr’s picture

Status: Needs work » Needs review
StatusFileSize
new2.69 KB
new15.48 KB

Fixing the last tests

duaelfr’s picture

I think you don't need my phpunit.xml file :/
Sorry again

duaelfr’s picture

Assigned: duaelfr » Unassigned
Issue summary: View changes
Issue tags: +Needs screenshots, +Novice, +Needs manual testing

We could use screenshots here and there is some manual testing to do.
Novices are welcome!

agomezmoron’s picture

Issue summary: View changes
Issue tags: -Needs screenshots, -Needs manual testing
StatusFileSize
new11.57 KB
new5.93 KB
new15.85 KB
new120.9 KB

After applying the patch #30, I checked that is worked on:

Chrome

58.0.3029
57.0.2987

Firefox

52.0.1
52.0
51.0.1
51.0

Also screenshots are added (PRE and POST patch).

I also updated the summary with the tasks done.

mgifford’s picture

@agomezmoron want to mark it RTBC?

agomezmoron’s picture

Status: Needs review » Reviewed & tested by the community

@mgifford sure!

mgifford’s picture

Nice!

andrewmacpherson’s picture

Thanks for moving this patch along @DuaelFr. Getting it to RTBC way ahead of the 8.4.x releases will give site builders plenty of time to road-test it. Hopefully we can move the related issues along soon after.

agomezmoron’s picture

Issue summary: View changes
wim leers’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs usability review, +Needs issue summary update

AFAICT this needs usability review. The IS (issue summary) should also have a before vs after screenshot. Those screenshots already exist in #32, but should be added to the IS so that they're easy to find for a core committer and a usability maintainer.

andrewmacpherson’s picture

Issue tags: +Needs change record

I've looked at the child & related issues. I don't think any of these are blockers to this issue:

Does this warrant a change record, or a handbook update? It's a powerful feature for site builders, and themers should probably be made aware of this in case their custom themes are doing any fancy with block labels.

andrewmacpherson’s picture

Issue tags: +Documentation

Looking at the hook_help() in block.module...

For all blocks you can change the block title and toggle whether to display it.

Does "toggle" imply a boolean, with 2 options only? Maybe we can say "... and choose how to display it."
Do we need to explain the visually hidden option on the block help page?

andrewmacpherson’s picture

Issue summary: View changes

Correcting the "done" status for some tasks in issue summary, update the usability review task.

andrewmacpherson’s picture

This issue has moved forward considerably, and it makes sense to treat the Bartik header issue as a follow-up to this one. I've marked this issue as the parent for #2625834: Make the visibility of block titles in the header optional..

agomezmoron’s picture

Should it be moved it into Needs Review? I think it doesn't make sense keeping it in Needs Work.

yoroy’s picture

Issue tags: -Needs usability review +usabillity

Thanks for a solid issue summary and task list! I think adding this is a good idea. Some UI considerations:

3 options in a dropdown is not really nice :-\ I know this is similar to label visibility in Field UI, but that's consistency with a not so good user interface so we can allow some room to experiment here.

Accessibility-wise, is it even a good idea to have the option to exclude the title from the html output? Could we make this a boolean that toggles between show title and visually hidden? Put differently: is visually-hidden preferable over hidden?

andrewmacpherson’s picture

@yoroy

3 options in a dropdown is not really nice :-\ I know this is similar to label visibility in Field UI, but that's consistency with a not so good user interface so we can allow some room to experiment here.

So the other straight-forward approach is 3 radio buttons. It this preferable in your view? I'm agnostic, but I can see how seeing all options will help, when there are just a few.

Accessibility-wise, is it even a good idea to have the option to exclude the title from the html output?

Accessibility is the whole reason for this feature request. The intent is to provide better control for the document outline of the page, considered as a whole.

There is certainly an accessibility case for allowing blocks without heading elements. It allows you to group some related blocks under the same heading. Even though the content comes from separate blocks in the CMS, it sometimes deserves to be treated as one section in the document outline for the resulting page. The existing options allow you to do this; you can include the heading for the first block, and omit it from the subsequent block. The blocks are just wrapped in separate divs, so semantically they appear under the same heading in the document outline.

is visually-hidden preferable over hidden?

The answer depends entirely on the content!

Right now you have to decide between a visible heading, or no heading at all for each block. For the sake of visual presentation a heading may be undesirable, but when the block offers some important functionality a hidden heading will help some users. This is especially the case for blocks which contain form elements (search, login, sign-up). The current options encourage authors to compromise the document outline for the sake of visual presentation. This is the situation which the new visually-hidden option is intended to help with.

Could we make this a boolean that toggles between show title and visually hidden?

This would force site authors to include a heading for every block, which is swapping one problem for another. A visually-hidden heading will often be preferable to no heading, but forcing a heading for every block would still hinder efforts to achieve a sensible document outline for the whole page.

To confuse matters, some blocks already behave inconsistently. These are good things to address in follow-up issues (i.e. remove these constraints, allow site builders to exercise discretion, and provide good defaults).

yoroy’s picture

Issue summary: View changes
StatusFileSize
new54.32 KB

I tried to come up with another way to go about this that at least initially looks quite compact, at least more compact than 3 radio buttons. Not sure I like it: very wordy and not sure it's that much clearer. My goal was to make this work more like a single choice about how to change the default of "show title". If you choose to check the box you get a second option to refine what "do not show" should mean.

*Edit* initially showed an earlier version of this design, updated the link to show the latest.

yoroy’s picture

StatusFileSize
new564.25 KB
duaelfr’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

What if we used the working version, which is totally standard and looks like any other similar thing in core, THEN in a follow-up, discuss about improving it? I'd like to get things done for accessibility first. Usability is great, but we are overthinking the problem this time.

I updated IS to add the screenshots

duaelfr’s picture

Status: Needs work » Needs review

See the previous comment

mgifford’s picture

This sounds like a good way to move forward to me. I've re-queued the patch in #30 and am fine with the idea of moving this new pattern into a separate issue.

Status: Needs review » Needs work

The last submitted patch, 30: visually-hidden-block-titles-2614950-30.patch, failed testing. View results

duaelfr’s picture

Status: Needs work » Needs review

Rerolled #30

duaelfr’s picture

It's better with the file :)

mgifford’s picture

Totally Agree @DuaelFr - you're totally teasing us though.. :)

duaelfr’s picture

Sorry, I don't know what happened twice :/

yoroy’s picture

Yes, it's ok to start with the already existing pattern for how core handles this. I wasn't too happy with the other ideas yet either :)

flocondetoile’s picture

So, according to #38 and #56, can we RTBC this issue ? Is there yet remaining tasks ? Writing a change record is it really necessary ?

duaelfr’s picture

Status: Needs review » Reviewed & tested by the community

Let's try to move it forward.
See #32, #38, #48 and #56.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 55: visually-hidden-block-titles-2614950-55.patch, failed testing. View results

andypost’s picture

Issue tags: +Needs reroll

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

duaelfr’s picture

Version: 8.5.x-dev » 8.4.x-dev
Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new3.46 KB
new14 KB

Rerolled after #2785047: In Outside In mode, form validation messages should appear in the off-canvas tray, not the main page got commited (conflict solved interdiff attached)
I still hope it can go into 8.4 as the issue was RTBC before the alpha

Status: Needs review » Needs work

The last submitted patch, 62: visually-hidden-block-titles-2614950-62.patch, failed testing. View results

naveenvalecha’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new79.3 KB

Here's the straight reroll of the patch.

naveenvalecha’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new15.36 KB

Here's the correct patch with correct status

The last submitted patch, 64: 2904915-50.patch, failed testing. View results

The last submitted patch, 64: 2904915-50.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 65: 2614950-50.patch, failed testing. View results

naveenvalecha’s picture

Status: Needs work » Needs review

Fixed the block module failures. Still having failures with SettingsTrayBlockFormTest

naveenvalecha’s picture

StatusFileSize
new15.44 KB

Status: Needs review » Needs work

The last submitted patch, 70: 2614950-69.patch, failed testing. View results

duaelfr’s picture

Version: 8.4.x-dev » 8.5.x-dev
Status: Needs work » Needs review
Issue tags: -Novice
StatusFileSize
new15.47 KB

Finalized the fix for 8.5 (I can't run the tests locally so I hope the testbot is gonna be happy)

Status: Needs review » Needs work

The last submitted patch, 72: visually-hidden-block-titles-2614950-72.patch, failed testing. View results

duaelfr’s picture

Status: Needs work » Needs review
StatusFileSize
new2.03 KB
new101.52 KB

Fixed the test failure
+ Fixed an issue where the block title field in the settings tray was not shown when needed

Status: Needs review » Needs work

The last submitted patch, 74: visually-hidden-block-titles-2614950-74.patch, failed testing. View results

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

duaelfr’s picture

Status: Needs work » Needs review
StatusFileSize
new18.13 KB

Straight reroll of #74

Status: Needs review » Needs work

The last submitted patch, 78: visually-hidden-block-titles-2614950-78.patch, failed testing. View results

edmonkey’s picture

StatusFileSize
new44.8 KB

From an WCAG accessibility viewpoint, I would also be looking for the 'completely remove title from output' configuration per block.

Having a heading rendered in some cases causes both heading structure issues (see image of H2 above H1), and generate superfluous headings which aren't helpful for users of assistive technologies (screen readers etc).

snapshot of WAVE toolbar rendering headings incorrectly

In some cases ARIA landmarks and HTML5 elements cover the need for menu/nav and search structure.

Any further dev/thoughts on this appreciated.

edmonkey’s picture

duaelfr’s picture

#80 the thing is that we currently only have an option to hide the title which is supposed to entirely remove it from the markup. But, some themes decided that for some blocks, like menu blocks, this could also mean to hide them visually to help users to navigate to these blocks by the heading jumping technique.
Be completing this issue, we could allow site builders to choose wisely which option they need.

andrewmacpherson’s picture

Re: #80

superfluous headings which aren't helpful for users of assistive technologies (screen readers etc) [...] In some cases ARIA landmarks and HTML5 elements cover the need for menu/nav and search structure.

Over the years, the WebAIM screen reader user surveys have consistently shown that headings are the mostly likely way someone will try to find their way around the page. (Although this apparently wasn't asked in survey 6...) Landmark regions are growing in popularity but a surprising (to me) number of users aren't aware of them yet.

That's just an aside, though. As @DuaelFr says in #82, this issue is really about giving authors finer control over all block titles, by making the same options available to all block types, instead of treating menu blocks differently.

Further down the line, we might let authors choose a heading level per block - which might be very nice when combined with the new layout builder. But that can be a follow-up issue.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

dqd’s picture

Thanks @duaelfr and the others working on this! That would be a massive improvement!

this issue is really about giving authors finer control over all block titles

+1!

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

kishor_kolekar’s picture

Re-rolled against 9.1.x. Kindly review a patch.

kishor_kolekar’s picture

StatusFileSize
new12.89 KB

The last submitted patch, visually-hidden-block-titles-2614950-88.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

The last submitted patch, visually-hidden-block-titles-2614950-88.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 89: visually-hidden-block-titles-2614950-88.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jaykandari’s picture

Status: Needs work » Needs review
StatusFileSize
new17.91 KB

Rerolling

Status: Needs review » Needs work

The last submitted patch, 93: reroll-2614950-93.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

raman.b’s picture

Status: Needs work » Needs review
StatusFileSize
new38.29 KB
new19.92 KB

This should resolve the majority of failed test cases

abhijith s’s picture

StatusFileSize
new38.4 KB
new86.66 KB

Applied patch #96 and it works fine.There will be visually hidden option available in the block title.
Adding screenshots

Block configuration:
after1

markup:
after2

abhijith s’s picture

Status: Needs review » Reviewed & tested by the community
dqd’s picture

Dreditor goes "green" and I cannot see any drawbacks here ATM. Testing was without flaws but I would love to hear an opinion from somebody who is more into core block module, looking at it to make sure we do not create any bad follow ups. +1 for the work on this!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 96: 2614950-96.patch, failed testing. View results

raman.b’s picture

Status: Needs work » Needs review
StatusFileSize
new38.38 KB
new1.16 KB

Resolving deprecation notice

barone’s picture

@raman.b tested #101 and i confirm that all 3 options are working as expected, follow the screenshots.

UI - Select with the 3 options
User UI

Front end: Visually hidden
Visually hidden

Front end: Hidden
Hidden

barone’s picture

One detail i just saw: Do we really need the - (dash + space) before the labels for Hidden and Visually hidden?

zebda’s picture

I tried both #89 and #93 on my 9.1 Drupal installation but they both cannot be applied. Since 9.2 is still in dev mode I prefer using 9.1.

"patches": {
    "drupal/core":{
        "Block Title Visually Hidden 9.1": "https://www.drupal.org/files/issues/2020-08-11/reroll-2614950-93.patch"
    }

Any idea what the problem could be?

bnjmnm’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/Block/BlockPluginInterface.php
    @@ -28,6 +28,19 @@
    +   * Indicates the block label (title) should hidden from end users.
    

    There's a missing "be" between should and hidden.

  2. +++ b/core/lib/Drupal/Core/Block/BlockPluginInterface.php
    @@ -28,6 +28,19 @@
    +   * @todo This value should be changed to "hidden" in Drupal 9.0.0 for
    +   *   consistency. See https://www.drupal.org/node/2863313.
    

    This @todo is referring to a Drupal version that has already released.

  3. +++ b/core/lib/Drupal/Core/Block/BlockPluginInterface.php
    @@ -28,6 +28,19 @@
    +   * Indicates the block label (title) should be visually-hidden from end users.
    

    Change "visually-hidden" to "visually hidden" and remove "from end users"

  4. +++ b/core/lib/Drupal/Core/Block/BlockPluginTrait.php
    @@ -171,10 +171,11 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
         $form['label_display'] = [
    -      '#type' => 'checkbox',
    +      '#type' => 'select',
           '#title' => $this->t('Display title'),
    -      '#default_value' => ($this->configuration['label_display'] === BlockPluginInterface::BLOCK_LABEL_VISIBLE),
    -      '#return_value' => BlockPluginInterface::BLOCK_LABEL_VISIBLE,
    +      '#description' => $this->t('How to display the block title.'),
    +      '#options' => $this->getLabelDisplayOptions(),
    +      '#default_value' => $this->configuration['label_display'],
         ];
    

    This presents a backwards compatibility issue for contrib/custom that may be altering this form element, it would be difficult to get a change such as this through all the core gates. If there were a way to accomplish this by *adding* a form element instead (even if the UX isn't as good), it's more likely to be accepted as a change to core. Otherwise, this would probably need to wait until D10

    An additional "make visually hidden" checkbox field that is only availavle when "visible" is selected may work. The value of that could conditionally add a .visually-hidden class. Not as elegant, but more likely to land.

  5. +++ b/core/lib/Drupal/Core/Block/BlockPluginTrait.php
    @@ -185,6 +186,20 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
    +      BlockPluginInterface::BLOCK_LABEL_HIDDEN => '- ' . $this->t('Hidden') . ' -',
    +      BlockPluginInterface::BLOCK_LABEL_VISUALLY_HIDDEN => '- ' . $this->t('Visually Hidden') . ' -',
    

    No dashes/spaces should be added here, particularly since these characters are used elsewhere to represent hierarchy, and there's no hierarchy to these options.

nikitagupta’s picture

StatusFileSize
new38.3 KB

Addressed #105.1,2,3,5

BarisW’s picture

Here is a re-roll of #78 for Drupal 8.9.x

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

sutharsan’s picture

Status: Needs work » Needs review
StatusFileSize
new18.31 KB

Re-roll of the #107 patch for Drupal 9.3.x.
Comments in #105 still need to be addressed.

Status: Needs review » Needs work

The last submitted patch, 109: visually-hidden-block-titles-2614950-109.patch, failed testing. View results

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

louisnagtegaal’s picture

Re-roll of the patch in #109. Removed no longer necessary diff for

core/modules/block/tests/modules/block_test/config/install/block.block.test_block.yml

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

idiaz.roncero’s picture

Rerolled patch in order to make it apply to 9.4.x version of Core.

There were (luckily) no conflicts to solve.

(edit: Forgot to attach the patch to this comment! as a result, the patch number is #114 but the comment will be #115, sorry)

idiaz.roncero’s picture

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

sahil.goyal’s picture

StatusFileSize
new17.66 KB
new9.79 KB

Tried to apply #114 patch but the given 9.5.x-dev version is not compatible with 10.1.x-dev so i reroll the patch and updated also attaching the reroll file.

pradhumanjain2311’s picture

Status: Needs work » Needs review
StatusFileSize
new17.57 KB
new3.28 KB

Try to fix patch #117 CCF errors.

Status: Needs review » Needs work

The last submitted patch, 118: 2614950-118.patch, failed testing. View results

bnjmnm’s picture

I'm not sure why #107 attempted to reroll patch #78, despite later patches adding essential changes. It looks like there have since been 5 attempts to re-reroll the failed reroll of patch #78, even though it omits several desirable changes that have been made since.

#106 would have been the best choice as it addressed several concerns / problems that were spotted after #78. At this point, however, I recommend no more rerolls and instead creating a new patch entirely that is inspired by but not a reroll of 106. As I mentioned in #105.4, the solution is changing the configuration form in a way that breaks backwards compatibility in a manner that prevents it from being committable.

+++ b/core/lib/Drupal/Core/Block/BlockPluginTrait.php
@@ -171,10 +171,11 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
     $form['label_display'] = [
-      '#type' => 'checkbox',
+      '#type' => 'select',
       '#title' => $this->t('Display title'),
-      '#default_value' => ($this->configuration['label_display'] === BlockPluginInterface::BLOCK_LABEL_VISIBLE),
-      '#return_value' => BlockPluginInterface::BLOCK_LABEL_VISIBLE,
+      '#description' => $this->t('How to display the block title.'),
+      '#options' => $this->getLabelDisplayOptions(),
+      '#default_value' => $this->configuration['label_display'],
     ];

Changing this from a checkbox to a select will break form_alters for any contrib/custom that uses it. If you instead add an element to the form to set visually hidden (AJAX could be used to only make this field available when 'Display Title' is true). The UX would be slightly worse, but this would not break form API usages AND many of the tests that had to be changed to support this new feature won't have to be because the 'label_display' would still work the same, just augmented by a newly introduced 'label_visually_hidden' option

katannshaw’s picture

I'd love to have this feature for our current client and I like @bnjmnm's suggestions in comment #120. Is this something being actively worked on?

fskreuz’s picture

StatusFileSize
new13.48 KB

Here's a reworked #106 based on comments from #105. Added a new configuration field label_display_type separate from the existing label_display checkbox that lets one select how one wants to hide the title. The hope would be that in a future version, label_display will just roll into the select box as the "visible" option, just like the patches prior. Name, label, and description could be better, open to suggestions.

Tests removed in this patch, I wasn't sure if they'd still be applicable (I also don't have a test-capable setup at the moment). Hopefully someone can pick up the baton from here.

mgifford’s picture

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

fskreuz’s picture

StatusFileSize
new13.6 KB

Updated #125 for 10.3.x

fskreuz’s picture

Status: Needs work » Needs review
StatusFileSize
new13.38 KB

Updated #125 for 10.3.x, take 2.

andypost’s picture

Utkarsh_33 made their first commit to this issue’s fork.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new6.15 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

guietc’s picture

StatusFileSize
new16.86 KB

Here is a new patch updated for Drupal 11
This update is based on the latest patch (#127), which I have rebased and adapted for compatibility with the 11.x branch.

mgifford’s picture

Status: Needs work » Needs review

This looks like it needs review @guietc.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

quietone’s picture

Issue tags: -usabillity +Usability

Tag cleanup

fskreuz’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new6.16 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

dhavalpanchal’s picture

StatusFileSize
new30.22 KB

The changes have been added as a patch file which is implemented in merge request 8596. The changes are working correctly on Drupal 11.3

liam morland made their first commit to this issue’s fork.

liam morland’s picture

Status: Needs work » Needs review

I have rebased the merge request.

Currently, when label_display is falsy, label is empty. It should be that label always contains the label. This would allow a template to have code like this:

{% if label and not label_display %}
  {% do attributes.setAttribute('aria-label', label) %}
{% endif %}
smustgrave’s picture

Status: Needs review » Needs work

Haven’t fully reviewed but tests are failing and CR is missing.

liam morland’s picture

Status: Needs work » Needs review

I have created a draft of a different approach in merge request 15613. What this change does is put the block title in an aria-label attribute when a label exists but it would not otherwise be displayed. I only did this change in the default template. If this approach is accepted, then the merge request can be updated to change this template in all themes and add tests.

smustgrave’s picture

Status: Needs review » Needs work

Think summary should be updated if 2 approaches are being proposed.

That said if a new one is done then remaining tasks will have to be updated as this will have to go through the same checks.

liam morland’s picture

The next step is to decide which approach to use.