Skip to content

Commit

Permalink
chore: add role property to aria helpers
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 632857688
  • Loading branch information
asyncLiz authored and copybara-github committed May 12, 2024
1 parent e77ce06 commit 7f3d9d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions internal/aria/aria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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';
}

/**
Expand All @@ -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-')
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/aria/aria_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 7f3d9d1

Please sign in to comment.