Skip to content

Commit 7f3d9d1

Browse files
asyncLizcopybara-github
authored andcommitted
chore: add role property to aria helpers
PiperOrigin-RevId: 632857688
1 parent e77ce06 commit 7f3d9d1

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

internal/aria/aria.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
/**
88
* Accessibility Object Model reflective aria property name types.
99
*/
10-
export type ARIAProperty = Exclude<keyof ARIAMixin, 'role'>;
10+
export type ARIAProperty = keyof ARIAMixin;
1111

1212
/**
1313
* Accessibility Object Model reflective aria properties.
1414
*/
1515
export const ARIA_PROPERTIES: ARIAProperty[] = [
16+
'role',
1617
'ariaAtomic',
1718
'ariaAutoComplete',
1819
'ariaBusy',
@@ -72,7 +73,7 @@ export const ARIA_ATTRIBUTES = ARIA_PROPERTIES.map(ariaPropertyToAttribute);
7273
* @return True if the attribute is an aria attribute, or false if not.
7374
*/
7475
export function isAriaAttribute(attribute: string): attribute is ARIAAttribute {
75-
return attribute.startsWith('aria-');
76+
return attribute.startsWith('aria-') || attribute === 'role';
7677
}
7778

7879
/**
@@ -84,9 +85,7 @@ export function isAriaAttribute(attribute: string): attribute is ARIAAttribute {
8485
* @param property The aria property.
8586
* @return The aria attribute.
8687
*/
87-
export function ariaPropertyToAttribute<K extends ARIAProperty | 'role'>(
88-
property: K,
89-
) {
88+
export function ariaPropertyToAttribute<K extends ARIAProperty>(property: K) {
9089
return (
9190
property
9291
.replace('aria', 'aria-')
@@ -101,8 +100,8 @@ type ARIAPropertyToAttribute<K extends string> =
101100
K extends `aria${infer Suffix}Element${infer OptS}`
102101
? `aria-${Lowercase<Suffix>}`
103102
: K extends `aria${infer Suffix}`
104-
? `aria-${Lowercase<Suffix>}`
105-
: K;
103+
? `aria-${Lowercase<Suffix>}`
104+
: K;
106105

107106
/**
108107
* An extension of `ARIAMixin` that enforces strict value types for aria

internal/aria/aria_test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ describe('aria', () => {
2222
.toBeTrue();
2323
});
2424

25-
it('should return false for role', () => {
26-
expect(isAriaAttribute('role')).withContext('role input').toBeFalse();
25+
it('should return true for role', () => {
26+
expect(isAriaAttribute('role')).withContext('role input').toBeTrue();
2727
});
2828

2929
it('should return false for non-aria attributes', () => {

0 commit comments

Comments
 (0)