Skip to content

Commit

Permalink
Fix aria null values (#5097)
Browse files Browse the repository at this point in the history
* fix: align aria null behavior between setting methods

* fix: setAttribute string case

* fix: revert missing stringify

* fix: revert deletion

* fix: revert setAttribute 'null' behavior change
  • Loading branch information
jhefferman-sfdc authored Jan 6, 2025
1 parent 891f3fb commit b2468c9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<template shadowrootmode="open">
<div>
</div>
<x-grandchild aria-activedescendant="null" aria-atomic="null" aria-autocomplete="null" aria-braillelabel="null" aria-brailleroledescription="null" aria-busy="null" aria-checked="null" aria-colcount="null" aria-colindex="null" aria-colindextext="null" aria-colspan="null" aria-controls="null" aria-current="null" aria-describedby="null" aria-description="null" aria-details="null" aria-disabled="null" aria-errormessage="null" aria-expanded="null" aria-flowto="null" aria-haspopup="null" aria-hidden="null" aria-invalid="null" aria-keyshortcuts="null" aria-label="null" aria-labelledby="null" aria-level="null" aria-live="null" aria-modal="null" aria-multiline="null" aria-multiselectable="null" aria-orientation="null" aria-owns="null" aria-placeholder="null" aria-posinset="null" aria-pressed="null" aria-readonly="null" aria-relevant="null" aria-required="null" aria-roledescription="null" aria-rowcount="null" aria-rowindex="null" aria-rowindextext="null" aria-rowspan="null" aria-selected="null" aria-setsize="null" aria-sort="null" aria-valuemax="null" aria-valuemin="null" aria-valuenow="null" aria-valuetext="null" role="null">
<x-grandchild>
<template shadowrootmode="open">
</template>
</x-grandchild>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<x-test aria-description="undefined" data-bar="null" data-foo="null" data-lwc-host-mutated="aria-description aria-label data-bar data-foo">
<x-test aria-describedby="undefined" aria-label="null" aria-labelledby="undefined" data-bar-set-attribute="null" data-foo-set-attribute="null" data-lwc-host-mutated="aria-describedby aria-description aria-label aria-labelledby data-bar-set-attribute data-foo-set-attribute">
<template shadowrootmode="open">
</template>
</x-test>
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
isNull = null;
connectedCallback() {
this.setAttribute('data-foo', 'foo');
this.setAttribute('data-foo', null);
this.setAttribute('data-bar', null);
// Non-aria set attribute should be "null"
this.setAttribute('data-foo-set-attribute', 'foo');
this.setAttribute('data-foo-set-attribute', null);
this.setAttribute('data-bar-set-attribute', null);

// Aria null (the attribute should be absent)
this.ariaDescription = 'awesome description';
this.ariaDescription = null;

// Aria null setAttribute (the attribute should be "null")
this.setAttribute('aria-label', 'awesome label');
this.ariaLabel = null;
this.setAttribute('aria-description', 'awesome description');
this.ariaDescription = undefined;
this.setAttribute('aria-label', null);

// Aria undefined (the attribute should be "undefined")
this.setAttribute('aria-describedby', 'awesome label');
this.setAttribute('aria-describedby', undefined);
this.ariaLabelledBy = 'id1';
this.ariaLabelledBy = undefined;
}
}
11 changes: 9 additions & 2 deletions packages/@lwc/engine-server/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,15 @@ function setProperty(node: N, propName: string, value: any): void {
: removeAttribute(node, attrName);
}

// Handle global html attributes and AOM.
if (REFLECTIVE_GLOBAL_PROPERTY_SET.has(propName) || isAriaAttribute(attrName)) {
if (isAriaAttribute(attrName)) {
// TODO [#3284]: According to the spec, IDL nullable type values
// (null and undefined) should remove the attribute; however, we
// only do so in the case of null for historical reasons.
return isNull(value)
? removeAttribute(node, attrName)
: setAttribute(node, attrName, value);
} else if (REFLECTIVE_GLOBAL_PROPERTY_SET.has(propName)) {
// Handle global html attributes and AOM.
return setAttribute(node, attrName, value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// We should slowly drive down these test failures or at least document where we expect the failures
// TODO [#4815]: enable all SSR v2 tests
export const expectedFailures = new Set([
'attribute-aria/dynamic/index.js',
'attribute-class/with-scoped-styles-only-in-child/dynamic/index.js',
'attribute-class/with-scoped-styles/dynamic/index.js',
'attribute-global-html/as-component-prop/undeclared/index.js',
Expand Down

0 comments on commit b2468c9

Please sign in to comment.