Skip to content

Commit aa6fedf

Browse files
fix: update aria-labelledby when restoring default label (#6085) (#6088)
Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
1 parent 87b9af9 commit aa6fedf

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

packages/component-base/src/slot-child-observe-controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class SlotChildObserveController extends SlotController {
169169
__updateNodeId(node) {
170170
// When in multiple mode, only set ID attribute on the element in default slot.
171171
const isFirstNode = !this.nodes || node === this.nodes[0];
172-
if (node.nodeType === Node.ELEMENT_NODE && isFirstNode && !node.id) {
172+
if (node.nodeType === Node.ELEMENT_NODE && (!this.multiple || isFirstNode) && !node.id) {
173173
node.id = this.defaultId;
174174
}
175175
}

packages/field-base/test/field-mixin.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ const runTests = (defineHelper, baseMixin) => {
774774
describe('slotted label', () => {
775775
beforeEach(async () => {
776776
element = fixtureSync(`
777-
<${tag}>
777+
<${tag} label="Default">
778778
<label slot="label">Label</label>
779779
<input slot="input">
780780
</${tag}>
@@ -789,6 +789,15 @@ const runTests = (defineHelper, baseMixin) => {
789789
expect(aria).to.be.ok;
790790
expect(aria).to.equal(label.id);
791791
});
792+
793+
it('should restore aria-labelledby when removing slotted label', async () => {
794+
label.remove();
795+
await nextRender();
796+
const defaultLabel = element.querySelector('[slot=label]');
797+
const aria = input.getAttribute('aria-labelledby');
798+
expect(aria).to.be.ok;
799+
expect(aria).to.equal(defaultLabel.id);
800+
});
792801
});
793802

794803
describe('aria-required', () => {

0 commit comments

Comments
 (0)