Skip to content

Commit 4ec43f4

Browse files
committed
fix(aria/combobox): readonly esc behavior
1 parent d5e7344 commit 4ec43f4

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/aria/combobox/combobox.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,13 @@ describe('Combobox', () => {
550550
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
551551
});
552552

553-
it('should clear selection on escape when closed', () => {
553+
it('should NOT clear selection on escape when closed', () => {
554554
focus();
555555
down();
556556
enter();
557557
expect(inputElement.value).toBe('Alabama');
558558
escape();
559-
expect(inputElement.value).toBe('');
559+
expect(inputElement.value).toBe('Alabama');
560560
});
561561
});
562562

@@ -1114,7 +1114,7 @@ describe('Combobox', () => {
11141114
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
11151115
});
11161116

1117-
it('should clear selection on escape when closed', () => {
1117+
it('should NOT clear selection on escape when closed', () => {
11181118
focus();
11191119
down();
11201120
right();
@@ -1123,7 +1123,7 @@ describe('Combobox', () => {
11231123
expect(inputElement.value).toBe('December');
11241124
expect(inputElement.getAttribute('aria-expanded')).toBe('false');
11251125
escape();
1126-
expect(inputElement.value).toBe('');
1126+
expect(inputElement.value).toBe('December');
11271127
});
11281128
});
11291129
});

src/aria/private/combobox/combobox.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -604,14 +604,14 @@ describe('Combobox with Listbox Pattern', () => {
604604
expect(combobox.expanded()).toBe(false);
605605
});
606606

607-
it('should clear selection on escape when already closed', () => {
607+
it('should NOT clear selection on escape when already closed', () => {
608608
const {combobox, listbox} = getPatterns({readonly: true});
609609
combobox.onPointerup(clickOption(listbox.inputs.items(), 2));
610610
expect(listbox.getSelectedItem()).toBe(listbox.inputs.items()[2]);
611611
expect(listbox.inputs.value()).toEqual(['Banana']);
612612
combobox.onKeydown(escape());
613-
expect(listbox.getSelectedItem()).toBe(undefined);
614-
expect(listbox.inputs.value()).toEqual([]);
613+
expect(listbox.getSelectedItem()).toBe(listbox.inputs.items()[2]);
614+
expect(listbox.inputs.value()).toEqual(['Banana']);
615615
});
616616
});
617617
});
@@ -943,16 +943,16 @@ describe('Combobox with Tree Pattern', () => {
943943
expect(combobox.expanded()).toBe(false);
944944
});
945945

946-
it('should clear selection on escape when already closed', () => {
946+
it('should NOT clear selection on escape when already closed', () => {
947947
const {combobox, tree, inputEl} = getPatterns({readonly: true});
948948
combobox.onPointerup(clickInput(inputEl));
949949
combobox.onPointerup(clickTreeItem(tree.inputs.allItems(), 0));
950950
expect(tree.inputs.value()).toEqual(['Fruit']);
951951
expect(inputEl.value).toBe('Fruit');
952952
expect(combobox.expanded()).toBe(false);
953953
combobox.onKeydown(escape());
954-
expect(tree.inputs.value()).toEqual([]);
955-
expect(inputEl.value).toBe('');
954+
expect(tree.inputs.value()).toEqual(['Fruit']);
955+
expect(inputEl.value).toBe('Fruit');
956956
});
957957
});
958958
});

src/aria/private/combobox/combobox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
383383

384384
const popupControls = this.inputs.popupControls();
385385

386-
if (!this.expanded()) {
386+
if (!this.expanded() && !this.readonly()) {
387387
this.inputs.inputValue?.set('');
388388
popupControls?.clearSelection();
389389

0 commit comments

Comments
 (0)