-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(synthetic): consider ancestors when determining click-focusability (
#1383) * test: reproduce bug described by issue #1382 * fix: consider ancestors when determining focusability
- Loading branch information
Showing
9 changed files
with
121 additions
and
10 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
67 changes: 67 additions & 0 deletions
67
...target-natively-non-focusable/delegates-focus-click-target-natively-non-focusable.spec.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,67 @@ | ||
/* | ||
* 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 | ||
*/ | ||
const assert = require('assert'); | ||
|
||
const URL = 'http://localhost:4567/delegates-focus-click-target-natively-non-focusable'; | ||
|
||
describe('when the click target is natively non-focusable', () => { | ||
beforeEach(() => { | ||
browser.url(URL); | ||
}); | ||
|
||
it('should apply focus to natively focusable parent (button) when click target is custom element', () => { | ||
const input = browser.execute(function() { | ||
return document | ||
.querySelector('integration-delegates-focus-click-target-natively-non-focusable') | ||
.shadowRoot.querySelector('.head'); | ||
}); | ||
input.click(); | ||
|
||
// Click on the custom element wrapped by the button | ||
const child = browser.execute(function() { | ||
return document | ||
.querySelector('integration-delegates-focus-click-target-natively-non-focusable') | ||
.shadowRoot.querySelector('integration-parent') | ||
.shadowRoot.querySelector('button > integration-child'); | ||
}); | ||
child.click(); | ||
|
||
const className = browser.execute(function() { | ||
return document | ||
.activeElement.shadowRoot.activeElement.shadowRoot.activeElement.className; | ||
}).value; | ||
|
||
// The invalid behavior described in issue #1382 causes focus to land on input.tail | ||
assert.equal(className, 'integration-child-button'); | ||
}); | ||
|
||
it('should apply focus to natively focusable parent (button) when click target is span element', () => { | ||
const input = browser.execute(function() { | ||
return document | ||
.querySelector('integration-delegates-focus-click-target-natively-non-focusable') | ||
.shadowRoot.querySelector('.head'); | ||
}); | ||
input.click(); | ||
|
||
// Click on the span wrapped by the button | ||
const span = browser.execute(function() { | ||
return document | ||
.querySelector('integration-delegates-focus-click-target-natively-non-focusable') | ||
.shadowRoot.querySelector('integration-parent') | ||
.shadowRoot.querySelector('button > span'); | ||
}); | ||
span.click(); | ||
|
||
const className = browser.execute(function() { | ||
return document | ||
.activeElement.shadowRoot.activeElement.shadowRoot.activeElement.className; | ||
}).value; | ||
|
||
// The invalid behavior described in issue #1382 causes focus to land on input.tail | ||
assert.equal(className, 'span-button'); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
...ity/test-delegates-focus-click-target-natively-non-focusable/integration/child/child.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,3 @@ | ||
<template> | ||
<div>integration-child content</div> | ||
</template> |
3 changes: 3 additions & 0 deletions
3
...ility/test-delegates-focus-click-target-natively-non-focusable/integration/child/child.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,3 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class Child extends LightningElement {} |
5 changes: 5 additions & 0 deletions
5
...ck-target-natively-non-focusable/delegates-focus-click-target-natively-non-focusable.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,5 @@ | ||
<template> | ||
<input class="head" placeholder="head"> | ||
<integration-parent tabindex="-1"></integration-parent> | ||
<input class="tail" placeholder="tail"> | ||
</template> |
3 changes: 3 additions & 0 deletions
3
...lick-target-natively-non-focusable/delegates-focus-click-target-natively-non-focusable.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,3 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class Container extends LightningElement {} |
3 changes: 3 additions & 0 deletions
3
...ty/test-delegates-focus-click-target-natively-non-focusable/integration/parent/parent.css
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,3 @@ | ||
:focus { | ||
border-color: red; | ||
} |
8 changes: 8 additions & 0 deletions
8
...y/test-delegates-focus-click-target-natively-non-focusable/integration/parent/parent.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,8 @@ | ||
<template> | ||
<button class="integration-child-button"> | ||
<integration-child></integration-child> | ||
</button> | ||
<button class="span-button"> | ||
<span>span content</span> | ||
</button> | ||
</template> |
5 changes: 5 additions & 0 deletions
5
...ity/test-delegates-focus-click-target-natively-non-focusable/integration/parent/parent.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,5 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class Parent extends LightningElement { | ||
static delegatesFocus = true; | ||
} |