Skip to content

Commit 8600905

Browse files
committed
fix(combobox): prevent disabled combobox from swapping custom/input values on click (#1699)
1 parent 4724070 commit 8600905

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

packages/dropdowns.next/src/elements/combobox/Combobox.spec.tsx

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,45 @@ describe('Combobox', () => {
407407
expect(input).toHaveFocus();
408408
});
409409

410-
it('handles `renderValue` as expected', () => {
411-
const { getByTestId } = render(
412-
<TestCombobox renderValue={({ selection }) => `test-${(selection as ISelectedOption).value}`}>
413-
<Option isSelected value="value" />
414-
</TestCombobox>
415-
);
416-
const input = getByTestId('input');
410+
describe('`renderValue`', () => {
411+
it('handles custom value as expected', async () => {
412+
const { getByTestId } = render(
413+
<TestCombobox
414+
renderValue={({ selection }) => `test-${(selection as ISelectedOption).value}`}
415+
>
416+
<Option isSelected value="value" />
417+
</TestCombobox>
418+
);
419+
const combobox = getByTestId('combobox');
420+
const trigger = combobox.firstChild as HTMLElement;
421+
const input = getByTestId('input');
422+
423+
await user.click(trigger);
417424

418-
expect(input).toHaveValue('value');
419-
expect(input.previousSibling).toHaveTextContent('test-value');
425+
expect(input).not.toHaveAttribute('hidden');
426+
expect(input).toHaveValue('value');
427+
expect(input.previousSibling).toHaveTextContent('test-value');
428+
});
429+
430+
it('handles disabled with custom value as expected', async () => {
431+
const { getByTestId } = render(
432+
<TestCombobox
433+
isDisabled
434+
renderValue={({ selection }) => `test-${(selection as ISelectedOption).value}`}
435+
>
436+
<Option isSelected value="value" />
437+
</TestCombobox>
438+
);
439+
const combobox = getByTestId('combobox');
440+
const trigger = combobox.firstChild as HTMLElement;
441+
const input = getByTestId('input');
442+
443+
await user.click(trigger);
444+
445+
expect(input).toHaveAttribute('hidden');
446+
expect(input).toHaveValue('value');
447+
expect(input.previousSibling).toHaveTextContent('test-value');
448+
});
420449
});
421450

422451
describe('validation', () => {

packages/dropdowns.next/src/elements/combobox/Combobox.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,14 @@ export const Combobox = forwardRef<HTMLDivElement, IComboboxProps>(
188188
validation,
189189
...(getTriggerProps({
190190
onFocus: () => {
191-
if (isEditable) {
192-
setIsInputHidden(false);
193-
}
191+
if (!isDisabled) {
192+
if (isEditable) {
193+
setIsInputHidden(false);
194+
}
194195

195-
if (isMultiselectable) {
196-
setIsTagGroupExpanded(true);
196+
if (isMultiselectable) {
197+
setIsTagGroupExpanded(true);
198+
}
197199
}
198200
},
199201
onBlur: event => {

0 commit comments

Comments
 (0)