mirror of
https://github.com/material-components/material-web.git
synced 2024-10-05 17:48:16 +03:00
chore: add role property to aria helpers
PiperOrigin-RevId: 632857688
This commit is contained in:
parent
e77ce061b6
commit
7f3d9d1bdf
@ -7,12 +7,13 @@
|
||||
/**
|
||||
* Accessibility Object Model reflective aria property name types.
|
||||
*/
|
||||
export type ARIAProperty = Exclude<keyof ARIAMixin, 'role'>;
|
||||
export type ARIAProperty = keyof ARIAMixin;
|
||||
|
||||
/**
|
||||
* Accessibility Object Model reflective aria properties.
|
||||
*/
|
||||
export const ARIA_PROPERTIES: ARIAProperty[] = [
|
||||
'role',
|
||||
'ariaAtomic',
|
||||
'ariaAutoComplete',
|
||||
'ariaBusy',
|
||||
@ -72,7 +73,7 @@ export const ARIA_ATTRIBUTES = ARIA_PROPERTIES.map(ariaPropertyToAttribute);
|
||||
* @return True if the attribute is an aria attribute, or false if not.
|
||||
*/
|
||||
export function isAriaAttribute(attribute: string): attribute is ARIAAttribute {
|
||||
return attribute.startsWith('aria-');
|
||||
return attribute.startsWith('aria-') || attribute === 'role';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,9 +85,7 @@ export function isAriaAttribute(attribute: string): attribute is ARIAAttribute {
|
||||
* @param property The aria property.
|
||||
* @return The aria attribute.
|
||||
*/
|
||||
export function ariaPropertyToAttribute<K extends ARIAProperty | 'role'>(
|
||||
property: K,
|
||||
) {
|
||||
export function ariaPropertyToAttribute<K extends ARIAProperty>(property: K) {
|
||||
return (
|
||||
property
|
||||
.replace('aria', 'aria-')
|
||||
@ -101,8 +100,8 @@ type ARIAPropertyToAttribute<K extends string> =
|
||||
K extends `aria${infer Suffix}Element${infer OptS}`
|
||||
? `aria-${Lowercase<Suffix>}`
|
||||
: K extends `aria${infer Suffix}`
|
||||
? `aria-${Lowercase<Suffix>}`
|
||||
: K;
|
||||
? `aria-${Lowercase<Suffix>}`
|
||||
: K;
|
||||
|
||||
/**
|
||||
* An extension of `ARIAMixin` that enforces strict value types for aria
|
||||
|
@ -22,8 +22,8 @@ describe('aria', () => {
|
||||
.toBeTrue();
|
||||
});
|
||||
|
||||
it('should return false for role', () => {
|
||||
expect(isAriaAttribute('role')).withContext('role input').toBeFalse();
|
||||
it('should return true for role', () => {
|
||||
expect(isAriaAttribute('role')).withContext('role input').toBeTrue();
|
||||
});
|
||||
|
||||
it('should return false for non-aria attributes', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user