Skip to content
Closed
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
48 changes: 48 additions & 0 deletions test-app/tests/integration/components/combobox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,54 @@ module('Integration | Component | <Combobox>', function (hooks) {

assert.dom(getComboboxInput()).hasValue('B');
});

test('selecting an option puts the display value into Combobox.Input when displayValue is provided and values are objects', async function (assert) {
this.set('onChange', (value) => {
this.set('value', value);
});

this.setProperties({
value: null,
a: { value: 'a' },
b: { value: 'b' },
c: { value: 'c' },
displayValue: (option) => {
return option?.value?.toUpperCase() || 'None';
},
});

await render(hbs`
<Combobox
@value={{this.value}}
@onChange={{this.onChange}}
as |combobox|
>
<combobox.Input @displayValue={{this.displayValue}}/>
<combobox.Button data-test="headlessui-combobox-button-2">Trigger</combobox.Button>
<combobox.Options as |options|>
<options.Option @value={{this.a}}>Option A</options.Option>
<options.Option @value={{this.b}}>Option B</options.Option>
<options.Option @value={{this.c}}>Option C</options.Option>
</combobox.Options>
</Combobox>
`);

await click(getComboboxButton());
assertComboboxList({ state: ComboboxState.Visible });

await click(getComboboxOptions()[1]);
assert.dom(getComboboxInput()).hasValue('B');

await click(getComboboxButton());
assertComboboxList({ state: ComboboxState.Visible });

assert.dom(getComboboxInput()).hasValue('B');

await click(document.body);
assertComboboxList({ state: ComboboxState.InvisibleUnmounted });

assert.dom(getComboboxInput()).hasValue('B');
});
});

module('Combobox.Label', () => {
Expand Down