Skip to content

Commit 3cc5cd3

Browse files
fix(polyfill): change aria-descrbedby to aria-labelledby
1 parent 0c1ee3d commit 3cc5cd3

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

Diff for: src/element-internals.js

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class ElementInternals {
6868
}
6969

7070
setValidity(validityChanges, validationMessage) {
71+
const ref = refMap.get(this);
7172
if (!validityChanges) {
7273
throw new TypeError('Failed to execute \'setValidity\' on \'ElementInternals\': 1 argument required, but only 0 present.');
7374
}
@@ -84,6 +85,7 @@ class ElementInternals {
8485
}
8586

8687
validationMessageMap.set(this, valid ? '' : validationMessage);
88+
ref.setAttribute('aria-invalid', !valid);
8789
this.reportValidity();
8890
}
8991

Diff for: src/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const initLabels = (ref, labels) => {
4040
label.addEventListener('click', ref.focus.bind(ref)));
4141
const firstLabelId = `${labels[0].htmlFor}_Label`;
4242
labels[0].id = firstLabelId;
43-
ref.setAttribute('aria-describedby', firstLabelId);
43+
ref.setAttribute('aria-labelledby', firstLabelId);
4444
}
4545
};
4646

Diff for: static/scripts/foo-bar.js

+12
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export class FooBar extends HTMLElement {
4646

4747
_init() {
4848
this.input.addEventListener('input', this._handleChanges);
49+
50+
if (this.required) {
51+
this._handleRequired(this.value);
52+
}
4953
}
5054

5155
_handleChanges(event) {
@@ -74,6 +78,14 @@ export class FooBar extends HTMLElement {
7478
this.internals_.setFormValue('');
7579
}
7680

81+
get required() {
82+
return this.hasAttribute('required');
83+
}
84+
85+
set required(required) {
86+
this.setAttribute('aria-required', !!required);
87+
}
88+
7789
get value() {
7890
return this._value;
7991
}

Diff for: static/scripts/page.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const testRoot = div.attachShadow({ mode: 'open' });
2020
const shadowForm = document.createElement('form');
2121
shadowForm.id = 'shadowTestForm';
2222
const fooBar = document.createElement('foo-bar');
23+
fooBar.required = true;
2324
testRoot.append(shadowForm);
2425
testRoot.append(fooBar);
2526
setTimeout(() => {

0 commit comments

Comments
 (0)