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(select-rich): block arrow key interaction when singleOption is set #2474

Merged
merged 1 commit into from
Feb 13, 2025
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
5 changes: 5 additions & 0 deletions .changeset/rare-walls-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lion/ui': patch
---

[select-rich] block arrow key interaction when singleOption is set
2 changes: 1 addition & 1 deletion packages/ui/components/select-rich/src/LionSelectRich.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ export class LionSelectRich extends SlotMixin(ScopedElementsMixin(OverlayMixin(L
*/
// TODO: rename to #invokerOnKeyUp() (and move event listener to the invoker) in v1
__onKeyUp(ev) {
if (this.disabled || this.readOnly) {
if (this.disabled || this.readOnly || this.singleOption) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,31 @@ describe('lion-select-rich', () => {
expect(elSingleoption.opened).to.be.false;
});

it('stays closed with [ArrowUp] or [ArrowDown] key in readonly mode', async () => {
it('stays closed with [ArrowUp] or [ArrowDown] key in readonly mode or has a single option', async () => {
const elReadOnly = await fixture(html`
<lion-select-rich readonly>
<lion-option .choiceValue=${10}>Item 1</lion-option>
<lion-option .choiceValue=${20} checked>Item 2</lion-option>
</lion-select-rich>
`);

const elSingleOption = await fixture(html`
<lion-select-rich>
<lion-option .choiceValue=${10}>Item 1</lion-option>
</lion-select-rich>
`);

elReadOnly.dispatchEvent(new KeyboardEvent('keyup', { key: 'ArrowDown' }));
expect(elReadOnly.opened).to.be.false;

elReadOnly.dispatchEvent(new KeyboardEvent('keyup', { key: 'ArrowUp' }));
expect(elReadOnly.opened).to.be.false;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these events be fired from focusable element (invokerNode)?

And should they bubble? (Or wrap them in a mimic method that uses sendKeys?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is on the lion-select-rich directly. It already has an todo next to the function to move it to the invoker.
It wouldn't hurt to wrap them in a mimic method. But let's do that in a future task.

elSingleOption.dispatchEvent(new KeyboardEvent('keyup', { key: 'ArrowDown' }));
expect(elSingleOption.opened).to.be.false;

elSingleOption.dispatchEvent(new KeyboardEvent('keyup', { key: 'ArrowUp' }));
expect(elSingleOption.opened).to.be.false;
});

it('sets inheritsReferenceWidth to min by default', async () => {
Expand Down