Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(engine): handling AOM properties on anchor tags #488

Merged
merged 1 commit into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/lwc-engine/src/framework/__tests__/issue-487.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { createElement, LightningElement } from '../main';

describe('issue 487', () => {
it('should not throw when setting AOM property on anchor', () => {
class MyComponent extends LightningElement {
setAriaSelected() {
this.template.querySelector('a').ariaSelected = 'true';
}
render() {
return function ($api, $cmp) {
return [
$api.h('a', { key: 0 }, []),
]
}
}
}

MyComponent.publicMethods = ['setAriaSelected'];

const element = createElement('x-foo', { is: MyComponent }) as HTMLAnchorElement;
document.body.appendChild(element);
element.href = 'https://google.com';
expect(() => {
element.setAriaSelected();
}).not.toThrow();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ function getAriaPropertyMap(elm: HTMLElement): AriaPropMap {
}

function isShadowRoot(elmOrShadow: Element | ShadowRoot): elmOrShadow is ShadowRoot {
return 'host' in elmOrShadow;
return !(elmOrShadow instanceof Element) && 'host' in elmOrShadow;
}

function isSignedCustomElement(elmOrShadow: Element | ShadowRoot): elmOrShadow is HTMLElement {
return !('host' in elmOrShadow) && getNodeKey(elmOrShadow) !== undefined;
return !isShadowRoot(elmOrShadow) && getNodeKey(elmOrShadow) !== undefined;
}

function getNormalizedAriaPropertyValue(propName: string, value: any): any {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const assert = require('assert');
describe('Setting AOM property on anchor tag', () => {
const URL = 'http://localhost:4567/anchor-aom-setter';
let element;

before(() => {
browser.url(URL);
});

it('should set AOM property without error', function () {
browser.click('button');
assert.deepEqual(browser.getText('.error-text'), 'no error');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<a href="#">Anchor</a>
<button onclick={handleClick}>Click Me</button>
<div class="error-text">{errorText}</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Element, track } from 'engine';

export default class AnchorAOMSetter extends Element {
@track errorText = 'no error';
handleClick() {
try {
this.template.querySelector('a').ariaLabel = 'label';
} catch (e) {
this.errorText = e.message;
}
}
}