-
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 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 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
70 changes: 68 additions & 2 deletions
70
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
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,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(); | ||
| } | ||
|
|
||
| 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; | ||
|
|
||
| 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); | ||
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,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); |
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); |
47 changes: 47 additions & 0 deletions
47
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,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
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); |
Oops, something went wrong.
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.