Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
65bb519
add for-label story and demo target component
myrta2302 Aug 18, 2025
8997167
Merge branch 'main' into add-for-label-stories-in-the-accessibility-s…
myrta2302 Aug 29, 2025
49a5f66
finish for -label stories and components
myrta2302 Aug 29, 2025
42fc24b
add aria-labelledby story and web components
myrta2302 Sep 1, 2025
700a4da
added aria-describedby and list-role stories
myrta2302 Sep 8, 2025
427be41
updated stories
myrta2302 Sep 9, 2025
9699f89
fix lint error
myrta2302 Sep 9, 2025
0c78e0d
fix code smells
myrta2302 Sep 9, 2025
203609c
Merge branch 'main' into add-for-label-stories-in-the-accessibility-s…
myrta2302 Sep 9, 2025
03bef8d
fix lint error
myrta2302 Sep 9, 2025
add563a
Merge branch 'add-for-label-stories-in-the-accessibility-section' of …
myrta2302 Sep 9, 2025
9ad9489
Merge branch 'main' into add-for-label-stories-in-the-accessibility-s…
myrta2302 Sep 9, 2025
a4fee21
updatesd aria-labelledby stories with more information and examples
myrta2302 Sep 12, 2025
c57fa88
lint error
myrta2302 Sep 12, 2025
82b04de
update examples as per review comments
myrta2302 Sep 16, 2025
1ed58d5
update wording
myrta2302 Sep 16, 2025
4e0a1a0
minor example updates
myrta2302 Sep 16, 2025
c5853a2
updated examples as per review comments
myrta2302 Sep 22, 2025
4c93d04
update role="list" examples and text
myrta2302 Sep 24, 2025
4b65941
Merge branch 'main' into add-for-label-stories-in-the-accessibility-s…
myrta2302 Sep 24, 2025
f7fd9a9
revert file
myrta2302 Sep 24, 2025
c8a8803
added intro cross reference table
myrta2302 Sep 24, 2025
b64f4e1
lint error
myrta2302 Sep 24, 2025
ca323a5
Merge branch 'main' into add-for-label-stories-in-the-accessibility-s…
myrta2302 Nov 5, 2025
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,78 @@
# post-popover-trigger

# post-popover

# post-popover-trigger

<!-- Auto Generated Below -->


## Properties

| Property | Attribute | Description | Type | Default |
| --------------------------------- | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `arrow` | `arrow` | Show a little indicator arrow | `boolean` | `true` |
| `closeButtonCaption` _(required)_ | `close-button-caption` | Define the caption of the close button for assistive technology | `string` | `undefined` |
| `placement` | `placement` | Defines the position of the popover relative to its trigger. Popovers are automatically flipped to the opposite side if there is not enough available space and are shifted towards the viewport if they would overlap edge boundaries. For supported values and behavior details, see the [Floating UI placement documentation](https://floating-ui.com/docs/computePosition#placement). | `"bottom" \| "bottom-end" \| "bottom-start" \| "left" \| "left-end" \| "left-start" \| "right" \| "right-end" \| "right-start" \| "top" \| "top-end" \| "top-start"` | `'top'` |


## Methods

### `hide() => Promise<void>`

Programmatically hide this popover

#### Returns

Type: `Promise<void>`



### `show(target: HTMLElement) => Promise<void>`

Programmatically display the popover

#### Parameters

| Name | Type | Description |
| -------- | ------------- | ---------------------------------------------------------------------------- |
| `target` | `HTMLElement` | An element with [data-popover-target="id"] where the popover should be shown |

#### Returns

Type: `Promise<void>`



### `toggle(target: HTMLElement, force?: boolean) => Promise<void>`

Toggle popover display

#### Parameters

| Name | Type | Description |
| -------- | ------------- | ---------------------------------------------------------------------------------- |
| `target` | `HTMLElement` | An element with [data-popover-target="id"] where the popover should be anchored to |
| `force` | `boolean` | Pass true to always show or false to always hide |

#### Returns

Type: `Promise<void>`




## Dependencies

### Depends on

- [post-popovercontainer](../post-popovercontainer)

### Graph
```mermaid
graph TD;
post-popover --> post-popovercontainer
style post-popover fill:#f9f,stroke:#333,stroke-width:4px
```

| Property | Attribute | Description | Type | Default |
| ------------------ | --------- | --------------------------------------------------------------------------------------------- | -------- | ----------- |
| `for` _(required)_ | `for` | ID of the popover element that this trigger is linked to. Used to open and close the popover. | `string` | `undefined` |
Expand Down
2 changes: 2 additions & 0 deletions packages/documentation/.storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import './styles/preview.scss';
import { SyntaxHighlighter } from 'storybook/internal/components';
import scss from 'react-syntax-highlighter/dist/esm/languages/prism/scss';

import '../src/demo-components';

SyntaxHighlighter.registerLanguage('scss', scss);

export const SourceDarkScheme = true;
Expand Down
83 changes: 83 additions & 0 deletions packages/documentation/src/demo-components/demo-button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
export class DemoButton extends HTMLElement {
static get observedAttributes() {
return ['button-version', 'workaround', 'arialabelledby-id', 'ariadescribedby-id'];
}
private buttonVersion?: '1' | '2' | '3' | '4';
private workaround?: string;
private internalButton?: HTMLElement;
private arialabelledbyId?: string;
private ariadescribedbyId?: string;
private slotEl?: HTMLSlotElement;

constructor() {
super();
this.attachShadow({ mode: 'open' });
}

connectedCallback() {
this.render();
}

attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
if (name === 'workaround') this.workaround = newValue;
if (name === 'arialabelledby-id') this.arialabelledbyId = newValue;
if (name === 'ariadescribedby-id') this.ariadescribedbyId = newValue;
if (name === 'button-version') this.buttonVersion = newValue as '1' | '2' | '3';
this.render();
}
Comment on lines +21 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since only the observed attributes will execute this callback, you could easily make it generic.

attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
  const member = name.replace(/-./g, m => m[1].toUpperCase());
  
  this[member] = newValue;
  this.render();
}


private setupAria() {
const isLabelled = this.workaround === 'ariaLabelledByElements';
const isDescribed = this.workaround === 'ariaDescribedByElements';

if (!this.internalButton || (!isLabelled && !isDescribed)) {
return;
}

let elementToLink: Element | null = null;

if (this.buttonVersion === '1' || this.buttonVersion === '3') {
const id = isLabelled ? this.arialabelledbyId : this.ariadescribedbyId;
if (id) {
elementToLink = document.querySelector(`#${id}`);
}
} else if (this.buttonVersion === '2' || this.buttonVersion === '4') {
if (this.slotEl) {
const assignedElements = this.slotEl.assignedElements({ flatten: true });
elementToLink = assignedElements.find(el => el.tagName === 'SPAN') || null;
}
}

const ariaPropertyName = isLabelled ? 'ariaLabelledByElements' : 'ariaDescribedByElements';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a so called "good practice" to define variables at the beginning of a function. Please move this to line 32.

this.internalButton[ariaPropertyName] = elementToLink ? [elementToLink] : [];
}

private render() {
if (!this.shadowRoot) return;

if (this.buttonVersion) {
this.shadowRoot.innerHTML = `
<slot name="aria-slot"></slot>
<div part="button"
role="button"
tabindex="0"
> <post-icon name="1022"></post-icon>
</div>
`;
} else {
this.shadowRoot.innerHTML = `
<span id="example">My Text</span>
<div part="button"
role="button" tabindex="0" aria-labelledby="example">
<post-icon name="1022"></post-icon>
</div>
`;
}

this.internalButton = this.shadowRoot.querySelector('div[role="button"]') as HTMLElement;
this.slotEl = this.shadowRoot.querySelector('slot[name="aria-slot"]') as HTMLSlotElement;
this.setupAria();
}
}

customElements.define('demo-button', DemoButton);
90 changes: 90 additions & 0 deletions packages/documentation/src/demo-components/demo-input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
export class DemoInput extends HTMLElement {
static get observedAttributes() {
return ['workaround', 'arialabelledby-id', 'target-version'];
}

private workaround?: string;
private arialabelledbyId?: string;
private targetVersion?: '1' | '2' | '3';
private internalEl?: HTMLElement;
private slotEl?: HTMLSlotElement;

constructor() {
super();
this.attachShadow({ mode: 'open' });
}

connectedCallback() {
this.render();
}

attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
if (name === 'workaround') this.workaround = newValue;
if (name === 'arialabelledby-id') this.arialabelledbyId = newValue;
if (name === 'target-version') this.targetVersion = newValue as '1' | '2' | '3';

this.render();
}

private setupAriaLabelledBy() {
if (!this.internalEl) {
return;
}

let elementToLink: Element | null = null;
const isLabelledByWorkaround = this.workaround === 'ariaLabelledByElements';

if (this.targetVersion === '1') {
if (isLabelledByWorkaround && this.arialabelledbyId) {
elementToLink = document.querySelector(`[for="${this.arialabelledbyId}"]`);
}
} else if (this.targetVersion === '2') {
if (isLabelledByWorkaround && this.slotEl) {
const assignedElements = this.slotEl.assignedElements({ flatten: true });
elementToLink = assignedElements.find(el => el.tagName === 'LABEL') || null;
}
} else if (this.targetVersion === '3') {
if (this.arialabelledbyId) {
elementToLink = document.querySelector(`#${this.arialabelledbyId}`);
}
}

this.internalEl.ariaLabelledByElements = elementToLink ? [elementToLink] : [];
}

private render() {
if (!this.shadowRoot) return;
//Version #2
if (this.targetVersion === '2') {
this.shadowRoot.innerHTML = `
<slot name="aria-slot"></slot>
<input id="internal">
`;
this.slotEl = this.shadowRoot.querySelector('slot[name="aria-slot"]') as HTMLSlotElement;
this.internalEl = this.shadowRoot.querySelector('#internal') as HTMLElement;
} else if (this.targetVersion === '3') {
// Version #3
this.shadowRoot.innerHTML = `
<input id="internal">
`;
this.internalEl = this.shadowRoot.querySelector('#internal') as HTMLElement;
} else if (this.targetVersion === '1') {
// Version #1
this.shadowRoot.innerHTML = `
<input id="internal">
<slot></slot>
`;
this.internalEl = this.shadowRoot.querySelector('#internal') as HTMLElement;
} else {
// Version default
this.shadowRoot.innerHTML = `
<label for="example">My Text</label>
<input id="example">
`;
}

this.setupAriaLabelledBy();
}
}

customElements.define('demo-input', DemoInput);
31 changes: 31 additions & 0 deletions packages/documentation/src/demo-components/demo-label.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export class DemoLabel extends HTMLElement {
static get observedAttributes() {
return ['for'];
}

private for!: string;

constructor() {
super();
this.attachShadow({ mode: 'open' });
}

connectedCallback() {
this.render();
}

attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
if (name === 'for') this.for = newValue;

this.render();
}

private render() {
if (!this.shadowRoot) return;
this.shadowRoot.innerHTML = `
<label>My Text</label>
`;
}
}

customElements.define('demo-label', DemoLabel);
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export class DemoListItemGroup extends HTMLElement {
static get observedAttributes() {
return ['list-group-version'];
}

private listGroupVersion?: number;

constructor() {
super();
this.attachShadow({ mode: 'open' });
}

attributeChangedCallback(name: string, _oldValue: number, newValue: number) {
if (name === 'list-group-version') this.listGroupVersion = newValue;

this.render();
}

connectedCallback() {
this.render();
}

private render() {
if (!this.shadowRoot) return;
if (this.listGroupVersion == 1) {
this.shadowRoot.innerHTML = `
<slot name="list-item"></slot>
`;
} else if (this.listGroupVersion == 2) {
this.shadowRoot.innerHTML = `<slot name="list-parent"></slot>
<div role="listitem">item 1</div>
<div role="listitem">item 2</div>
<div role="listitem">item 3</div>`;
} else if (this.listGroupVersion == 3) {
this.shadowRoot.innerHTML = `
<div role="listitem">item 1</div>
<div role="listitem">item 2</div>
<div role="listitem">item 3</div>`;
} else if (this.listGroupVersion == 4) {
this.shadowRoot.innerHTML = `
<slot></slot>
`;
}
}
}

customElements.define('demo-list-item-group', DemoListItemGroup);
20 changes: 20 additions & 0 deletions packages/documentation/src/demo-components/demo-list-item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export class DemoListItem extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
}

connectedCallback() {
this.render();
}

private render() {
if (!this.shadowRoot) return;
this.shadowRoot.innerHTML = `
<div role="listitem">
<slot></slot>
</div>`;
}
}

customElements.define('demo-list-item', DemoListItem);
Loading
Loading