Skip to content

Commit

Permalink
fix(feature-section-card-link): remove incorrect role (#8197)
Browse files Browse the repository at this point in the history
### Related Ticket(s)

Resolves #8010 

### Description

The `DDSLinkList` and `DDSFeatureSectionCardLink` components had incorrect `role` attributes, which caused a number of a11y errors to be reported when running the `yarn lint:a11y` script. Fixing the roles on these two components resolves any errors related to incorrect usages of "listitem" roles.

### Changelog

**Changed**

- Added `role="list"` to `DDSLinkList` component
- Removed `role="listitem"` from `DDSFeatureSectionCardLink` component

<!-- React and Web Component deploy previews are enabled by default. -->
<!-- To enable additional available deploy previews, apply the following -->
<!-- labels for the corresponding package: -->
<!-- *** "package: services": Services -->
<!-- *** "package: utilities": Utilities -->
<!-- *** "RTL": React / Web Components (RTL) -->
<!-- *** "feature flag": React / Web Components (experimental) -->
  • Loading branch information
jkaeser authored Feb 5, 2022
1 parent 3f31311 commit e68d4a1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license
*
* Copyright IBM Corp. 2020, 2021
* Copyright IBM Corp. 2020, 2022
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand All @@ -21,13 +21,6 @@ const { stablePrefix: ddsPrefix } = ddsSettings;
*/
@customElement(`${ddsPrefix}-feature-section-card-link`)
class DDSFeatureSectionCardLink extends DDSCardCTA {
connectedCallback() {
if (!this.hasAttribute('role')) {
this.setAttribute('role', 'listitem');
}
super.connectedCallback();
}

static get stableSelector() {
return `${ddsPrefix}--feature-section-card-link`;
}
Expand Down
7 changes: 7 additions & 0 deletions packages/web-components/src/components/link-list/link-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ class DDSLinkList extends StableSelectorMixin(LitElement) {
@property({ reflect: true })
type = LINK_LIST_TYPE.DEFAULT;

connectedCallback() {
if (!this.hasAttribute('role')) {
this.setAttribute('role', 'list');
}
super.connectedCallback();
}

render() {
const { type, _endTypeLayout: endTypeLayout } = this;
const headingClasses = classMap({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license
*
* Copyright IBM Corp. 2020, 2021
* Copyright IBM Corp. 2020, 2022
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -45,6 +45,10 @@ class DDSTopNavItem extends BXHeaderNavItem {

firstUpdated() {
this.shadowRoot?.querySelectorAll('[role="menuitem"]').forEach(menuItem => menuItem.removeAttribute('role'));

if (this.hasAttribute('role') && this.getAttribute('role') === 'listitem') {
this.removeAttribute('role');
}
}

static styles = styles; // `styles` here is a `CSSResult` generated by custom WebPack loader
Expand Down

0 comments on commit e68d4a1

Please sign in to comment.