-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(synthetic-shadow): programmatic focus when delegating focus (#1722)
* feat: focus method with shadow semantics https://html.spec.whatwg.org/multipage/interaction.html#focus-processing-model - The shadow host is never considered as a focusable area - If the shadow host does not contain any possible focus delegates, then return
- Loading branch information
Showing
37 changed files
with
431 additions
and
35 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 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
32 changes: 32 additions & 0 deletions
32
...nents/delegates-focus-programmatic/test-backwards-compatible/backwards-compatible.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,32 @@ | ||
/* | ||
* 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 = '/backwards-compatible'; | ||
|
||
describe('when the component overrides the focus method', () => { | ||
beforeEach(() => { | ||
browser.url(URL); | ||
}); | ||
|
||
it('should continue custom focus behavior', function() { | ||
browser.execute(function() { | ||
return document | ||
.querySelector('integration-backwards-compatible') | ||
.shadowRoot.querySelector('integration-child') | ||
.focus(); | ||
}); | ||
const className = browser.execute(function() { | ||
var active = document.activeElement; | ||
while (active.shadowRoot) { | ||
active = active.shadowRoot.activeElement; | ||
} | ||
return active.className; | ||
}); | ||
assert.equal(className, 'internal-textarea'); | ||
}); | ||
}); |
4 changes: 4 additions & 0 deletions
4
...atic/test-backwards-compatible/integration/backwards-compatible/backwards-compatible.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 @@ | ||
<template> | ||
<button onclick={handleClick}>focus</button> | ||
<integration-child tabindex="0"></integration-child> | ||
</template> |
7 changes: 7 additions & 0 deletions
7
...mmatic/test-backwards-compatible/integration/backwards-compatible/backwards-compatible.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,7 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class Container extends LightningElement { | ||
handleClick() { | ||
this.template.querySelector('integration-child').focus(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...nents/delegates-focus-programmatic/test-backwards-compatible/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,4 @@ | ||
<template> | ||
<input class="internal-input" placeholder="internal"> | ||
<textarea class="internal-textarea" placeholder="internal"></textarea> | ||
</template> |
10 changes: 10 additions & 0 deletions
10
...ponents/delegates-focus-programmatic/test-backwards-compatible/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,10 @@ | ||
import { LightningElement, api } from 'lwc'; | ||
|
||
export default class Child extends LightningElement { | ||
static delegatesFocus = true; | ||
|
||
@api | ||
focus() { | ||
this.template.querySelector('textarea').focus(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...es/integration-tests/src/components/delegates-focus-programmatic/test-basic/basic.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,28 @@ | ||
/* | ||
* 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 = '/basic'; | ||
|
||
describe('basic invocation', () => { | ||
beforeEach(() => { | ||
browser.url(URL); | ||
}); | ||
|
||
it('should focus on the first programmatically focusable element', function() { | ||
const button = browser.$(function() { | ||
return document.querySelector('integration-basic').shadowRoot.querySelector('button'); | ||
}); | ||
button.click(); | ||
const className = browser.execute(function() { | ||
const container = document.activeElement; | ||
const child = container.shadowRoot.activeElement; | ||
return child.shadowRoot.activeElement.className; | ||
}); | ||
assert.equal(className, 'internal-input'); | ||
}); | ||
}); |
4 changes: 4 additions & 0 deletions
4
...tests/src/components/delegates-focus-programmatic/test-basic/integration/basic/basic.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 @@ | ||
<template> | ||
<button onclick={handleClick}>focus</button> | ||
<integration-child tabindex="0"></integration-child> | ||
</template> |
7 changes: 7 additions & 0 deletions
7
...n-tests/src/components/delegates-focus-programmatic/test-basic/integration/basic/basic.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,7 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class Container extends LightningElement { | ||
handleClick() { | ||
this.template.querySelector('integration-child').focus(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...tests/src/components/delegates-focus-programmatic/test-basic/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,4 @@ | ||
<template> | ||
<input class="internal-input" placeholder="internal"> | ||
<textarea class="internal-textarea" placeholder="internal"></textarea> | ||
</template> |
5 changes: 5 additions & 0 deletions
5
...n-tests/src/components/delegates-focus-programmatic/test-basic/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,5 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class Child extends LightningElement { | ||
static delegatesFocus = true; | ||
} |
3 changes: 3 additions & 0 deletions
3
...ests/src/components/delegates-focus-programmatic/test-nested/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> | ||
<input class="child-input" placeholder="child-input"> | ||
</template> |
5 changes: 5 additions & 0 deletions
5
...-tests/src/components/delegates-focus-programmatic/test-nested/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,5 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class Child extends LightningElement { | ||
static delegatesFocus = true; | ||
} |
4 changes: 4 additions & 0 deletions
4
...ts/src/components/delegates-focus-programmatic/test-nested/integration/nested/nested.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 @@ | ||
<template> | ||
<button onclick={handleClick}>focus</button> | ||
<integration-parent tabindex="0"></integration-parent> | ||
</template> |
7 changes: 7 additions & 0 deletions
7
...ests/src/components/delegates-focus-programmatic/test-nested/integration/nested/nested.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,7 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class Container extends LightningElement { | ||
handleClick() { | ||
this.template.querySelector('integration-parent').focus(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ts/src/components/delegates-focus-programmatic/test-nested/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,3 @@ | ||
<template> | ||
<integration-child tabindex="0"></integration-child> | ||
</template> |
5 changes: 5 additions & 0 deletions
5
...ests/src/components/delegates-focus-programmatic/test-nested/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; | ||
} |
30 changes: 30 additions & 0 deletions
30
.../integration-tests/src/components/delegates-focus-programmatic/test-nested/nested.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,30 @@ | ||
/* | ||
* 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 = '/nested'; | ||
|
||
describe('when the only focusable element is in a nested shadow', () => { | ||
beforeEach(() => { | ||
browser.url(URL); | ||
}); | ||
|
||
it('should apply focus in the nested shadow', function() { | ||
const button = browser.$(function() { | ||
return document.querySelector('integration-nested').shadowRoot.querySelector('button'); | ||
}); | ||
button.click(); | ||
const className = browser.execute(function() { | ||
var active = document.activeElement; | ||
while (active.shadowRoot) { | ||
active = active.shadowRoot.activeElement; | ||
} | ||
return active.className; | ||
}); | ||
assert.equal(className, 'child-input'); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
.../delegates-focus-programmatic/test-noop-when-already-focused/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> | ||
<input class="child-input" placeholder="child-input"> | ||
</template> |
5 changes: 5 additions & 0 deletions
5
...ts/delegates-focus-programmatic/test-noop-when-already-focused/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,5 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class Child extends LightningElement { | ||
static delegatesFocus = true; | ||
} |
Oops, something went wrong.