article is the default role of an<article> and thus the attribute can be removed.

To test this, copy this snippet into the W3 validator: https://validator.w3.org/nu/#textarea

<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
</head>
<body>
<article role="article">
<h1>test</h1>
</article>
</body>
</html>

Also see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article

Comments

martijn.cuppens created an issue. See original summary.

martijn.cuppens’s picture

StatusFileSize
new363 bytes
kristen pol’s picture

Assigned: Unassigned » kristen pol
kristen pol’s picture

Thanks for the patch.

1) Reviewed the code and changes seem ok.

2) Patch applies cleanly:

[mac:kristen:drupal-9.1.x-dev]$ patch -p1 < 3117230-2.patch
patching file core/modules/node/node.module
Hunk #1 succeeded at 540 (offset 2 lines).

3) Searched the 9.1 dev code after applying the patch and there is this:

./core/themes/bartik/templates/comment.html.twig: <article role="article"{{ attributes.addClass(classes)|without('role') }}>

Should this be removed too since "article" is the default?

kristen pol’s picture

Assigned: kristen pol » Unassigned
Status: Needs review » Needs work

Whoops... unassigning. Also marking "Needs work" based on #4.3.

abhijeet.kumar2107’s picture

Assigned: Unassigned » abhijeet.kumar2107
Status: Needs work » Active
abhijeet.kumar2107’s picture

StatusFileSize
new941 bytes
new568 bytes

Hi @Kristen,
Yes, I checked and as mentioned in https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article
that role article belongs to "Implicit ARIA role" which will create redudant in some situations.

Rerolled patch from #2 with some modification mentioned at #4.3 .
Please review latest patch

abhijeet.kumar2107’s picture

Issue tags: +Srijancontribution2020
abhijeet.kumar2107’s picture

Assigned: abhijeet.kumar2107 » Unassigned
Status: Active » Needs review
idebr’s picture

Component: node system » markup
Status: Needs review » Needs work
+++ b/core/themes/bartik/templates/comment.html.twig
@@ -74,7 +74,7 @@
-<article role="article"{{ attributes.addClass(classes)|without('role') }}>
+<article {{ attributes.addClass(classes)|without('role') }}>
  1. Twig attributes are rendered with a space prefix, so there is no need for the space between <article and {{ attributes.
  2. The role attribute can now be printed, since it can no longer be added twice.
abhijeet.kumar2107’s picture

Assigned: Unassigned » abhijeet.kumar2107
martijn.cuppens’s picture

StatusFileSize
new936 bytes
martijn.cuppens’s picture

Assigned: abhijeet.kumar2107 » Unassigned
Status: Needs work » Needs review
kristen pol’s picture

Thanks for the update. Reviewing changes in #12 and looking at feedback from #10.

1. Twig attributes are rendered with a space prefix, so there is no need for the space between

Covered by update.

2. The role attribute can now be printed, since it can no longer be added twice.

Sorry, I don't understand this one.

martijn.cuppens’s picture

Sorry, I don't understand this one.

@Kristen Pol, there was a "|without('role')" formatter in the twig template, which I have removed:

<article role="article"{{ attributes.addClass(classes)|without('role') }}>

kristen pol’s picture

Ah, I think I figured it out. The interdiff in #7 doesn't have it but the patch does. That confused me because I thought it was already gone. Thanks for the clarification.

I think this just needs some manual testing now.

idebr’s picture

Title: Remove redundant role from node articles » Remove redundant role="article" from <article> html tags
Status: Needs review » Reviewed & tested by the community

The role="article" attribute was added for backwards compatibility with older browsers, specifically IE8 and earlier. Since we no longer support those browsers, this attribute can now be removed.

See browser support for <article> at https://caniuse.com/#feat=html5semantic

kristen pol’s picture

@idebr I'm confused because you added patches and marked RTBC. Also, I think this needs manual testing, no?

martijn.cuppens’s picture

The role="article" attribute was added for backwards compatibility with older browsers, specifically IE8 and earlier. Since we no longer support those browsers, this attribute can now be removed.

To be more precise, this was needed in browsers that didn't support HTML5.

Ref. https://www.w3.org/WAI/GL/wiki/Using_HTML5_article_element#Example_2:_Us...

kristen pol’s picture

To be clear, for manual testing, my thought was just to make sure the markup doesn't have the role. Unfortunately, I don't have time at the moment to double check.

kristen pol’s picture

I've done the manual testing to check it doesn't show up for the node or the comment.

Screenshots without patch:

Screenshots with patch:

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

This change looks good. I wonder if it is worth a change record? It's possible that someone has changed there node.twig.html to not use the article tag right? It's probably extremely rare and not something that should prevent the change but still informing themers seems the right thing to do.

alexpott’s picture

Also contrib code like https://git.drupalcode.org/project/adaptivetheme/-/blob/8.x-3.x/at_core/... is interesting as that adds the role. It'd be good to sure that browsers and accessibility tools are at one with the mozilla docs and W3 validator.

chi’s picture

For the record we have many other redundant usage of role attribute.

  • header role="banner"
  • main role="main"
  • footer role="contentinfo"
  • aside role="complementary"
  • nav role="navigation"
  • summary role="button"
andrewmacpherson’s picture

@chi - thanks for tagging this.

We should NOT remove the role="article" attribute from <article> for as long as we support IE11. I'm aware of the other roles mentioned in #24 - these should also remain. There is already a postponed issue to remove the landmark roles - #2655794: Remove redundant WAI-ARIA role attributes from <main>, <nav>, <aside>, <header>, and <footer> elements.

The reason for using the explicit ARIA roles, is that IE11 doesn't correctly map these implicit roles to the accessibility tree, and hence doesn't expose the correct semantics to the operating system's accessibility APIs.

I've given a more detailed explanation in at #2655794-14: Remove redundant WAI-ARIA role attributes from <main>, <nav>, <aside>, <header>, and <footer> elements and #2939485-2: Redundant attribute role="navigation" in Stable/Classy/Seven theme's pager.html.twig. Effectively, the explicit role="article" attribute serves as a polyfill for section 4.4 HTML Element Role Mappings in the HTML Accessibility API Mappings.

Comments #17 and #19 are incorrect. NO version of Internet Explorer has correctly mapped the implicit ARIA role for the <article> element (or any of the other elements mentioned in #24). Note that this is a separate issue from the use of a HTML5-shim, which was about getting IE to recognise the new HTML5 elements as being elements at all. Perhaps comments #17 and #19 have conflated it with that?

@alexpott - It would be a good idea for committers to request an accessibility review before removing a role attribute. There are lots of potential gotchas with removing a role attribute, which won't be apparent from reading the HTML recommendation on it's own. In this case, no comment has mentioned assistive tech support, which is the whole point of ARIA roles.

chi’s picture

footer role="contentinfo"

Voiceover does not assign correct role to footer without role attribte.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/footer#Accessi...

alexpott’s picture

@andrewmacpherson sorry for not tagging this one. OTOH at least I didn't commit it :) Should this be marked as a duplicate of #2655794: Remove redundant WAI-ARIA role attributes from <main>, <nav>, <aside>, <header>, and <footer> elements and included in the scope of that issue?

andrewmacpherson’s picture

#26: Thanks for adding that WebKit issue. Indeed, IE11 isn't the only browser that has accessibility bugs. We certainly shouldn't remove these while we still support IE11, but even when we drop support for IE11, these role attributes will still need to be reassessed for the other browsers. Apple seem to have a lot of trouble keeping Safari and VoiceOver stable, particularly on iOS. Each new release of iOS has a different batch of accessibility bugs. I haven't kept a close watch on them all, but AppleVis has a good collection of them. That particular contentinfo bug is interesting, because it isn't clear whether the fault lies with WebKit, VoiceOver, or Apple's AX API.

#27: I'm not sure if it should be marked as a duplicate of #2655794: Remove redundant WAI-ARIA role attributes from <main>, <nav>, <aside>, <header>, and <footer> elements, for a couple of reasons. Firstly, the roles over there are all landmark roles, but article isn't a landmark role. Not many screen reader do anything with the article role (just JAWS and Talkback so far), so the stakes are lower than for landmark roles. Secondly, for reasons such as #26, we may need to consider each role separately (not lumping them together to be removed at the same time) so the related issue may yet get split up.

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.

flotsam’s picture

For those of us wanting to remove role="article" from our deployment, is it possible to dig this out using a theme hook rather than a patch to core?

andrewmacpherson’s picture

#30 yes, you can probably remove the role attribute in a theme preprocess hook, or using a Twig without filter

But It's harmless, and there isn't a good reason to remove it.

flotsam’s picture

For those who wish to address this in a twig template file right in your theme, this can be easily changed using the attribute class in node.html.twig, like so:

<article{{ attributes.addClass(classes).removeAttribute('role') }}>

This was the solution that worked best for us.

@andrewmacpherson - while this is not much of an issue for most users, it's satisfying to move our theme into the future just a little quicker; it also helps with accessibility improvements (and reporting), since the role="article" attribute isn't needed and throws warnings. For tightening up the dom output, the attribute class is really a great helper.

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.

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.

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.

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.

mherchel’s picture

Issue summary: View changes
Status: Postponed » Active

Unpostponing (poning?) since Drupal 10 no longer supports IE11.

gauravvvv’s picture

Issue summary: View changes
Status: Active » Needs review

Removed role="article" from <article> tag. Attached patch for same. please review

gauravvvv’s picture

StatusFileSize
new1.19 KB
omkar_yewale’s picture

StatusFileSize
new114.28 KB
new102.93 KB

After manually reviewing #39 Patch, role="article" Removed from tag.

akshay kashyap’s picture

StatusFileSize
new140.26 KB
new32.56 KB

Verified and tested patch #39 on Drupal 10.1.x-dev. Patch was applied successfully and looks good to me.
Testing steps:
1. install Drupal 10.1.x
2. Check files UserPictureTest.php & node. module And find [role="article"] attribute.
3. apply the patch.
4. Observe that the [role="article"] attribute removed from the both files.

Testing Result:
1. [role="article"] attribute was removed after applying the patch. Screenshots are attached for reference:
Can be moved to RTBC"

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs change record +Needs Review Queue Initiative

As mentioned in https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/ar...

Don't use role="article". Instead use the element.

So this change looks good.

Not sure about the change record. If someone has overridden the template would say they have taken the responsibility upon themselves to be accessible. Even if they're embedding this just makes their site better.

But could be wrong.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 39: 3117230-38.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Random

  • catch committed 9bb75587 on 10.1.x
    Issue #3117230 by martijn.cuppens, abhijeet.kumar2107, Gauravvvv,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Agreed with @smustgrace on the lack of need for a change record, this is just removing something from preprocess.

I think we're find to go ahead here now that IE11 is no longer supported. I did copy @andrewmcpherson's comment from here over to #2655794: Remove redundant WAI-ARIA role attributes from <main>, <nav>, <aside>, <header>, and <footer> elements since we might want to be a bit more cautious there.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.