chore: add role property to aria helpers

PiperOrigin-RevId: 632857688
This commit is contained in:
Elizabeth Mitchell 2024-05-11 17:34:28 -07:00 committed by Copybara-Service
parent e77ce061b6
commit 7f3d9d1bdf
2 changed files with 8 additions and 9 deletions

View File

@ -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

View File

@ -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', () => {