Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/components/src/components/button/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { TooltipController } from '../../internal/functional-components/tooltip/
import type { AriaHasPopupPropType } from '../../schema/props/aria-has-popup';
import { validateAccessAndShortKey } from '../../schema/validators/access-and-short-key';
import clsx from '../../utils/clsx';
import { nonce } from '../../utils/dev.utils';
import { createCtaRef, directClick, directFocus } from '../../utils/element-interaction';
import { dispatchDomEvent, KolEvent } from '../../utils/events';
import { propagateResetEventToForm, propagateSubmitEventToForm } from '../form/controller';
Expand All @@ -78,6 +79,7 @@ export class KolButtonWc implements ButtonAPI, ClickableElement, FocusableElemen
@Element() protected readonly host?: HTMLKolButtonWcElement;
protected readonly ctaRef = createCtaRef<HTMLButtonElement>();
private readonly tooltipCtrl = new TooltipController(BaseWebComponent.stateLess);
private readonly internalDescriptionById = nonce();

/**
* Sets focus on the internal element.
Expand Down Expand Up @@ -148,7 +150,7 @@ export class KolButtonWc implements ButtonAPI, ClickableElement, FocusableElemen

public render(): JSX.Element {
const hasExpertSlot = showExpertSlot(this.state._label);
const ariaDescription = this.state._ariaDescription?.trim();
const hasAriaDescription = Boolean(this.state._ariaDescription?.trim()?.length);
const badgeText = this.state._accessKey || this.state._shortKey;
const isDisabled = this.state._disabled === true;
const hideLabel = this.state._hideLabel === true;
Expand All @@ -159,7 +161,7 @@ export class KolButtonWc implements ButtonAPI, ClickableElement, FocusableElemen
ref={this.ctaRef}
accessKey={this.state._accessKey}
aria-controls={this.state._ariaControls}
aria-description={ariaDescription || undefined}
aria-describedby={hasAriaDescription ? this.internalDescriptionById : undefined}
aria-expanded={mapBoolean2String(this.state._ariaExpanded)}
aria-haspopup={this._ariaHasPopup}
aria-keyshortcuts={this.state._shortKey}
Expand Down Expand Up @@ -198,6 +200,11 @@ export class KolButtonWc implements ButtonAPI, ClickableElement, FocusableElemen
/>
</div>
)}
{hasAriaDescription && (
<span class="visually-hidden" id={this.internalDescriptionById}>
{this.state._ariaDescription}
</span>
)}
</Host>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`kol-button should render with _label="Label" _ariaDescription="Aria Des
<template shadowrootmode="open">
<kol-button-wc>
<!---->
<button aria-description="Aria Description" class="kol-button kol-button--normal kol-button--standalone" type="button">
<button aria-describedby="nonce" class="kol-button kol-button--normal kol-button--standalone" type="button">
<span class="kol-button__text kol-span">
<span class="kol-span__container">
<span class="kol-span__label">
Expand All @@ -17,6 +17,9 @@ exports[`kol-button should render with _label="Label" _ariaDescription="Aria Des
</span>
</span>
</button>
<span class="visually-hidden" id="nonce">
Aria Description
</span>
</kol-button-wc>
</template>
</kol-button>
Expand Down
11 changes: 9 additions & 2 deletions packages/components/src/components/link/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
validateVariantClassName,
} from '../../schema';
import { validateTabIndex } from '../../schema/props/tab-index';
import { nonce } from '../../utils/dev.utils';
import { createCtaRef, directClick, directFocus } from '../../utils/element-interaction';
import { dispatchDomEvent, KolEvent } from '../../utils/events';
import type { UnsubscribeFunction } from './ariaCurrentService';
Expand All @@ -80,6 +81,7 @@ export class KolLinkWc implements ClickableElement, FocusableElement, InternalLi

protected readonly ctaRef = createCtaRef<HTMLAnchorElement>();
private readonly tooltipCtrl = new TooltipController(BaseWebComponent.stateLess);
private readonly internalDescriptionById = nonce();
private unsubscribeOnLocationChange?: UnsubscribeFunction;

private readonly translateOpenLinkInTab = translate('kol-open-link-in-tab');
Expand Down Expand Up @@ -154,7 +156,7 @@ export class KolLinkWc implements ClickableElement, FocusableElement, InternalLi
public render(): JSX.Element {
const { isExternal, tagAttrs } = this.getRenderValues();
const hasExpertSlot = showExpertSlot(this.state._label);
const ariaDescription = this.state._ariaDescription?.trim();
const hasAriaDescription = Boolean(this.state._ariaDescription?.trim()?.length);

return (
<Host>
Expand All @@ -164,7 +166,7 @@ export class KolLinkWc implements ClickableElement, FocusableElement, InternalLi
accessKey={this.state._accessKey}
aria-current={this.state._ariaCurrent}
aria-controls={this.state._ariaControls}
aria-description={ariaDescription || undefined}
aria-describedby={hasAriaDescription ? this.internalDescriptionById : undefined}
aria-disabled={this.state._disabled ? 'true' : undefined}
aria-expanded={typeof this.state._ariaExpanded === 'boolean' ? String(this.state._ariaExpanded) : undefined}
aria-owns={this.state._ariaOwns}
Expand Down Expand Up @@ -219,6 +221,11 @@ export class KolLinkWc implements ClickableElement, FocusableElement, InternalLi
/>
</div>
)}
{hasAriaDescription && (
<span class="visually-hidden" id={this.internalDescriptionById}>
{this.state._ariaDescription}
</span>
)}
</Host>
);
}
Expand Down
Loading