Skip to content

Commit

Permalink
🐛 it should be possible to open a listbox without submitting the form
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcnamara-eng committed Nov 5, 2021
1 parent 855f9e6 commit d14513a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions addon/components/listbox/-button.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{#let (element (or @as 'button')) as |Tag|}}
<Tag
role={{if @role @role 'button'}}
type={{if @type @type 'button'}}
id='{{@guid}}-button'
aria-haspopup='listbox'
aria-controls={{@guid}}
Expand Down
29 changes: 29 additions & 0 deletions tests/integration/components/listbox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3382,4 +3382,33 @@ module('Integration | Component | <Listbox>', function (hooks) {
assertNoActiveListboxOption();
});
});

test('should be possible to open a listbox without submitting the form', async function (assert) {
let callCount = 0;

this.set('onSubmit', () => {
callCount++;
});

await render(hbs`
<form {{on 'submit' this.onSubmit}}>
<Listbox as |listbox|>
<listbox.Button>Trigger</listbox.Button>
<listbox.Options as |options|>
<options.Option>option</options.Option>
</listbox.Options>
</Listbox>
</form>
`);
assertListboxButton({
state: ListboxState.InvisibleUnmounted,
});
assertListbox({
state: ListboxState.InvisibleUnmounted,
});
await click(getListboxButton());
assertListbox({ state: ListboxState.Visible });

assert.equal(callCount, 0, 'onSubmit not called');
});
});

0 comments on commit d14513a

Please sign in to comment.