Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 <listbox/> with transtion open on "enter" click #146

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions addon/components/listbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ export default class ListboxComponent extends Component {
} else {
this.isOpen = true;
}
event.preventDefault();
event.stopPropagation();
} else if (event.key.length === 1) {
this.addSearchCharacter(event.key);
}
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 @@ -10,6 +10,8 @@ import { hbs } from 'ember-cli-htmlbars';
import { module, skip, test, todo } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';

import userEvent from '@testing-library/user-event';

import {
assertActiveElement,
assertActiveListboxOption,
Expand Down Expand Up @@ -869,6 +871,33 @@ module('Integration | Component | <Listbox>', function (hooks) {
// Verify the active option is the previously selected one
assertActiveListboxOption(getListboxOptions()[0]);
});

test('should be possible to open the listbox (with transition) with "Enter"', async function (assert) {
await render(hbs`
<Listbox as |listbox|>
<listbox.Button data-test="headlessui-listbox-button-1">Trigger</listbox.Button>
<Transition
@show={{listbox.isOpen}}
>
<listbox.Options
@isOpen={{true}}
as |options|>
<options.Option>
Option A
</options.Option>
</listbox.Options>
</Transition>
</Listbox>`);

getListboxButton()?.focus();
userEvent.keyboard('{Enter}');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, triggerEvent from ember-helpers does not simulate "Enter" like real browser. Only one handler is executed, thus this test would pass even without a fix for the relevant issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the testing library util here do the whole series of events that occur when pressing keys?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, similar emulation we used with dialog test for tab press.


await assert.waitFor(async () => {
assertListbox({
state: ListboxState.Visible,
});
});
});
});

module('Listbox `Space` key', () => {
Expand Down