-
Notifications
You must be signed in to change notification settings - Fork 55
AdvancedTable focus bug fix
#4017
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
Open
zamoore
wants to merge
8
commits into
main
Choose a base branch
from
zamoore/hds-6545/AdvancedTable-focus-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+112
โ78
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3a6e608
fixed bug
zamoore 35785fc
updated tests
zamoore 3e9942f
addressing pr feedback
zamoore 4401ec9
reverted modifier change
zamoore a49bd04
removing invalid test
zamoore d666bd8
removing invalid test
zamoore 6085e9f
removed unneeded imports
zamoore 4e1eab3
removed unneeded imports
zamoore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| --- | ||
| "@hashicorp/design-system-components": patch | ||
| --- | ||
|
|
||
| `AdvancedTable` - Fixed an issue where clicking a cell scrolled the page to center that cell | ||
This file contains hidden or 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 hidden or 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
|
zamoore marked this conversation as resolved.
|
This file contains hidden or 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 hidden or 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 hidden or 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
127 changes: 127 additions & 0 deletions
127
showcase/tests/integration/modifiers/hds-scroll-into-view-test.gts
This file contains hidden or 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,127 @@ | ||
| /** | ||
| * Copyright IBM Corp. 2021, 2026 | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
|
|
||
| import { module, test } from 'qunit'; | ||
| import { render, find, focus } from '@ember/test-helpers'; | ||
| import sinon from 'sinon'; | ||
| import { hash } from '@ember/helper'; | ||
| import hdsScrollIntoViewOnFocus from '@hashicorp/design-system-components/modifiers/hds-scroll-into-view-on-focus'; | ||
|
|
||
| import { setupRenderingTest } from 'showcase/tests/helpers'; | ||
|
|
||
| module( | ||
| 'Integration | Modifier | hds-scroll-into-view-on-focus', | ||
| function (hooks) { | ||
| setupRenderingTest(hooks); | ||
|
|
||
| hooks.afterEach(function () { | ||
| sinon.restore(); | ||
| }); | ||
|
|
||
| test('it calls scrollIntoView with default options when focused', async function (assert) { | ||
| assert.expect(2); | ||
|
|
||
| const stub = sinon.stub(HTMLElement.prototype, 'scrollIntoView'); | ||
|
|
||
| await render( | ||
| <template> | ||
| <button id="target" type="button" {{hdsScrollIntoViewOnFocus}}> | ||
| Target | ||
| </button> | ||
| </template>, | ||
| ); | ||
|
|
||
| await focus('#target'); | ||
|
|
||
| assert.true(stub.calledOnce, 'scrollIntoView is called once on focus'); | ||
| assert.deepEqual(stub.firstCall.args[0], { | ||
| block: 'nearest', | ||
| inline: 'nearest', | ||
| }); | ||
| }); | ||
|
|
||
| test('it calls scrollIntoView with provided options when focused', async function (assert) { | ||
| assert.expect(2); | ||
|
|
||
| const stub = sinon.stub(HTMLElement.prototype, 'scrollIntoView'); | ||
|
|
||
| await render( | ||
| <template> | ||
| <button | ||
| id="target" | ||
| type="button" | ||
| {{hdsScrollIntoViewOnFocus | ||
| options=(hash block="center" inline="end" behavior="smooth") | ||
| }} | ||
| > | ||
| Target | ||
| </button> | ||
| </template>, | ||
| ); | ||
|
|
||
| await focus('#target'); | ||
|
|
||
| assert.true(stub.calledOnce, 'scrollIntoView is called once on focus'); | ||
| assert.deepEqual(stub.firstCall.args[0], { | ||
| block: 'center', | ||
| inline: 'end', | ||
| behavior: 'smooth', | ||
| }); | ||
| }); | ||
|
|
||
| test('it does not call scrollIntoView when focus is pointer-driven', async function (assert) { | ||
| assert.expect(1); | ||
|
|
||
| const stub = sinon.stub(HTMLElement.prototype, 'scrollIntoView'); | ||
|
|
||
| await render( | ||
| <template> | ||
| <button id="target" type="button" {{hdsScrollIntoViewOnFocus}}> | ||
| Target | ||
| </button> | ||
| </template>, | ||
| ); | ||
|
|
||
| const target = find('#target') as HTMLElement; | ||
| const matches = sinon.stub(target, 'matches').callThrough(); | ||
| matches.withArgs(':focus-visible').returns(false); | ||
|
|
||
| await focus('#target'); | ||
|
|
||
| assert.false( | ||
| stub.called, | ||
| 'scrollIntoView is not called for pointer-driven focus', | ||
| ); | ||
| }); | ||
|
|
||
| test('it does not call scrollIntoView when a descendant is focused', async function (assert) { | ||
| assert.expect(1); | ||
|
|
||
| const stub = sinon.stub(HTMLElement.prototype, 'scrollIntoView'); | ||
|
|
||
| await render( | ||
| <template> | ||
| <div id="parent" {{hdsScrollIntoViewOnFocus}}> | ||
| <button id="child" type="button"> | ||
| Child | ||
| </button> | ||
| </div> | ||
| </template>, | ||
| ); | ||
|
|
||
| // hold the ":focus-visible" guard open, otherwise it short circuites the handler | ||
| const target = find('#parent') as HTMLElement; | ||
| const matches = sinon.stub(target, 'matches').callThrough(); | ||
| matches.withArgs(':focus-visible').returns(false); | ||
|
|
||
| await focus('#child'); | ||
|
|
||
| assert.false( | ||
| stub.called, | ||
| 'scrollIntoView is not called when a descendant is focused', | ||
| ); | ||
| }); | ||
| }, | ||
| ); |
78 changes: 0 additions & 78 deletions
78
showcase/tests/integration/modifiers/hds-scroll-into-view.gts
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[todo] Add start and end comments around entry