fix(select-rich): readonly works with keyboard interaction (#2235)

This commit is contained in:
Wessam Zaghloul 2024-04-03 10:26:21 +02:00 committed by GitHub
parent f6b3f43a03
commit d2edadd3b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/ui': minor
---
[select-rich] fix readonly keyboard interaction

View file

@ -477,7 +477,7 @@ export class LionSelectRich extends SlotMixin(ScopedElementsMixin(OverlayMixin(L
*/
// TODO: rename to _onKeyUp in v1
__onKeyUp(ev) {
if (this.disabled) {
if (this.disabled || this.readOnly) {
return;
}

View file

@ -316,6 +316,21 @@ describe('lion-select-rich', () => {
expect(elSingleoption.opened).to.be.false;
});
it('stays closed with [ArrowUp] or [ArrowDown] key in readonly mode', 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>
`);
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;
});
it('sets inheritsReferenceWidth to min by default', async () => {
const el = await fixture(html`
<lion-select-rich name="favoriteColor" label="Favorite color">