-
Notifications
You must be signed in to change notification settings - Fork 396
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(engine): add ARIA reflection flag, fix SSR ARIA (#3197)
Fixes #3195
- Loading branch information
1 parent
5a8d405
commit 74b87da
Showing
42 changed files
with
603 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...lwc/aria-reflection-polyfill/package.json → packages/@lwc/aria-reflection/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
import { AriaPropNameToAttrNameMap, keys } from '@lwc/shared'; | ||
import { detect } from './detect'; | ||
import { patch } from './polyfill'; | ||
|
||
export function applyAriaReflection(prototype: any = Element.prototype) { | ||
const ElementPrototypeAriaPropertyNames = keys(AriaPropNameToAttrNameMap); | ||
|
||
for (let i = 0, len = ElementPrototypeAriaPropertyNames.length; i < len; i += 1) { | ||
const propName = ElementPrototypeAriaPropertyNames[i]; | ||
if (detect(propName, prototype)) { | ||
patch(propName, prototype); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
import { AriaPropNameToAttrNameMap, isNull, defineProperty } from '@lwc/shared'; | ||
|
||
function createAriaPropertyPropertyDescriptor(attrName: string): PropertyDescriptor { | ||
return { | ||
get(this: HTMLElement): any { | ||
// reflect what's in the attribute | ||
return this.hasAttribute(attrName) ? this.getAttribute(attrName) : null; | ||
}, | ||
set(this: HTMLElement, newValue: any) { | ||
// reflect into the corresponding attribute | ||
if (isNull(newValue)) { | ||
this.removeAttribute(attrName); | ||
} else { | ||
this.setAttribute(attrName, newValue); | ||
} | ||
}, | ||
configurable: true, | ||
enumerable: true, | ||
}; | ||
} | ||
|
||
export function patch(propName: string, prototype: any) { | ||
// Typescript is inferring the wrong function type for this particular | ||
// overloaded method: https://github.com/Microsoft/TypeScript/issues/27972 | ||
// @ts-ignore type-mismatch | ||
const attrName = AriaPropNameToAttrNameMap[propName]; | ||
const descriptor = createAriaPropertyPropertyDescriptor(attrName); | ||
defineProperty(prototype, propName, descriptor); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
import features from '@lwc/features'; | ||
import { applyAriaReflection } from '@lwc/aria-reflection'; | ||
|
||
if (!features.DISABLE_ARIA_REFLECTION_POLYFILL) { | ||
// If DISABLE_ARIA_REFLECTION_POLYFILL is false, then we need to apply the ARIA reflection polyfill globally, | ||
// i.e. to the global Element.prototype | ||
applyAriaReflection(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/@lwc/engine-server/src/__tests__/fixtures/attribute-aria-modify/expected.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<x-cmp aria-busy="true" aria-activedescendant="foo"> | ||
<template shadowroot="open"> | ||
</template> | ||
</x-cmp> |
2 changes: 2 additions & 0 deletions
2
packages/@lwc/engine-server/src/__tests__/fixtures/attribute-aria-modify/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const tagName = 'x-cmp'; | ||
export { default } from 'x/cmp'; |
2 changes: 2 additions & 0 deletions
2
...es/@lwc/engine-server/src/__tests__/fixtures/attribute-aria-modify/modules/x/cmp/cmp.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<template> | ||
</template> |
Oops, something went wrong.