-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(components/forms): set radio group 'aria-owns' to satisfy accessi…
…bility rules (#671)
- Loading branch information
1 parent
e78f849
commit 32f1e1e
Showing
10 changed files
with
165 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
51 changes: 51 additions & 0 deletions
51
libs/components/forms/src/lib/modules/radio/radio-group-id.service.ts
This file contains 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,51 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
import { BehaviorSubject, Observable } from 'rxjs'; | ||
|
||
/** | ||
* Tracks the element IDs for all radios within a radio group. | ||
* @internal | ||
*/ | ||
@Injectable() | ||
export class SkyRadioGroupIdService { | ||
public get radioIds(): Observable<string[]> { | ||
return this.#radioIdsObs; | ||
} | ||
|
||
#radioIds: Map<string, string>; | ||
#radioIds$: BehaviorSubject<string[]>; | ||
#radioIdsObs: Observable<string[]>; | ||
|
||
constructor() { | ||
this.#radioIds = new Map(); | ||
this.#radioIds$ = new BehaviorSubject<string[]>([]); | ||
this.#radioIdsObs = this.#radioIds$.asObservable(); | ||
} | ||
|
||
/** | ||
* Associates a radio input's ID with its parent radio group. | ||
* @param {string} id A unique ID for the radio component. | ||
* @param {string} inputElementId The ID applied to the radio input element. | ||
*/ | ||
public register(id: string, inputElementId: string): void { | ||
if (!this.#radioIds.has(id) || this.#radioIds.get(id) !== inputElementId) { | ||
this.#radioIds.set(id, inputElementId); | ||
this.#emitRadioIds(); | ||
} | ||
} | ||
|
||
/** | ||
* Disassociates a radio input's ID with its parent radio group. | ||
* @param {string} id The ID used to register the radio component. | ||
*/ | ||
public unregister(id: string): void { | ||
if (this.#radioIds.has(id)) { | ||
this.#radioIds.delete(id); | ||
this.#emitRadioIds(); | ||
} | ||
} | ||
|
||
#emitRadioIds(): void { | ||
this.#radioIds$.next(Array.from(this.#radioIds.values())); | ||
} | ||
} |
This file contains 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 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 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 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 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