-
Notifications
You must be signed in to change notification settings - Fork 21
feat(documentation): add accessibility reference relationship stories and demo components #6123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
myrta2302
wants to merge
24
commits into
main
Choose a base branch
from
add-for-label-stories-in-the-accessibility-section
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 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 8997167
Merge branch 'main' into add-for-label-stories-in-the-accessibility-sβ¦
myrta2302 49a5f66
finish for -label stories and components
myrta2302 42fc24b
add aria-labelledby story and web components
myrta2302 700a4da
added aria-describedby and list-role stories
myrta2302 427be41
updated stories
myrta2302 9699f89
fix lint error
myrta2302 0c78e0d
fix code smells
myrta2302 203609c
Merge branch 'main' into add-for-label-stories-in-the-accessibility-sβ¦
myrta2302 03bef8d
fix lint error
myrta2302 add563a
Merge branch 'add-for-label-stories-in-the-accessibility-section' of β¦
myrta2302 9ad9489
Merge branch 'main' into add-for-label-stories-in-the-accessibility-sβ¦
myrta2302 a4fee21
updatesd aria-labelledby stories with more information and examples
myrta2302 c57fa88
lint error
myrta2302 82b04de
update examples as per review comments
myrta2302 1ed58d5
update wording
myrta2302 4e0a1a0
minor example updates
myrta2302 c5853a2
updated examples as per review comments
myrta2302 4c93d04
update role="list" examples and text
myrta2302 4b65941
Merge branch 'main' into add-for-label-stories-in-the-accessibility-sβ¦
myrta2302 f7fd9a9
revert file
myrta2302 c8a8803
added intro cross reference table
myrta2302 b64f4e1
lint error
myrta2302 ca323a5
Merge branch 'main' into add-for-label-stories-in-the-accessibility-sβ¦
myrta2302 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
packages/components/src/components/post-popover-trigger/readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # post-popover | ||
|
|
||
|
|
||
|
|
||
| <!-- 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 | ||
| ``` | ||
|
|
||
| ---------------------------------------------- | ||
|
|
||
| *Built with [StencilJS](https://stenciljs.com/)* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| 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(); | ||
| } | ||
|
|
||
| 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'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| this.shadowRoot.innerHTML = ` | ||
| <slot name="label-slot"></slot> | ||
| <div part="button" | ||
| class="btn btn-primary" | ||
| role="button" | ||
| tabindex="0" | ||
| > <post-icon name="1022"></post-icon> | ||
| </div> | ||
| `; | ||
|
|
||
| this.internalButton = this.shadowRoot.querySelector('div[role="button"]') as HTMLElement; | ||
| this.slotEl = this.shadowRoot.querySelector('slot[name="label-slot"]') as HTMLSlotElement; | ||
| this.setupAria(); | ||
| } | ||
| } | ||
|
|
||
| customElements.define('demo-button', DemoButton); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
38 changes: 38 additions & 0 deletions
38
packages/documentation/src/demo-components/demo-list-item-group.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| 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="demo-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>`; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| customElements.define('demo-list-item-group', DemoListItemGroup); |
20 changes: 20 additions & 0 deletions
20
packages/documentation/src/demo-components/demo-list-item.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| export class DemoList extends HTMLElement { | ||
| static get observedAttributes() { | ||
| return ['list-version']; | ||
| } | ||
|
|
||
| private listVersion?: number; | ||
|
|
||
| constructor() { | ||
| super(); | ||
| this.attachShadow({ mode: 'open' }); | ||
| } | ||
|
|
||
| connectedCallback() { | ||
| this.render(); | ||
| } | ||
|
|
||
| attributeChangedCallback(name: string, _oldValue: number, newValue: number) { | ||
| if (name === 'list-version') this.listVersion = newValue; | ||
|
|
||
| this.render(); | ||
| } | ||
|
|
||
| private render() { | ||
| if (!this.shadowRoot) return; | ||
| if (this.listVersion == 1) { | ||
| this.shadowRoot.innerHTML = ` | ||
| <div> | ||
| <slot></slot> | ||
| </div> | ||
| `; | ||
| } else if (this.listVersion == 2) { | ||
| this.shadowRoot.innerHTML = ` | ||
| <div role="list" tabindex="0"> | ||
| <slot></slot> | ||
| </div> | ||
| `; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| customElements.define('demo-list', DemoList); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| export class DemoSpan extends HTMLElement { | ||
| static get observedAttributes() { | ||
| return ['spanId']; | ||
| } | ||
|
|
||
| private spanId!: string; | ||
|
|
||
| constructor() { | ||
| super(); | ||
| this.attachShadow({ mode: 'open' }); | ||
| } | ||
|
|
||
| connectedCallback() { | ||
| this.render(); | ||
| } | ||
|
|
||
| attributeChangedCallback(name: string, _oldValue: string, newValue: string) { | ||
| if (name === 'id') this.spanId = newValue; | ||
|
|
||
| this.render(); | ||
| } | ||
|
|
||
| private render() { | ||
| if (!this.shadowRoot) return; | ||
| this.shadowRoot.innerHTML = ` | ||
| <span>My Text</span> | ||
| `; | ||
| } | ||
| } | ||
|
|
||
| customElements.define('demo-span', DemoSpan); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.