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

support listbox with multiple selection #171

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

miguelcobain
Copy link

I ported all the tests for the multi-select from https://github.com/tailwindlabs/headlessui/blob/main/packages/%40headlessui-react/src/components/listbox/listbox.test.tsx

Let me know your feedback, please.

get selectedOptionGuid() {
return this.optionElements[this.selectedOptionIndex]?.id;
get selectedOptionGuids() {
return Array.from(this.selectedOptionIndexes).map(
Copy link
Collaborator

Choose a reason for hiding this comment

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

way make an array that ends up being a separate array each access?
does this need to be a getter?
can we access the optionElements directly?

@@ -181,15 +187,27 @@ export default class ListboxComponent extends Component {
optionElement.setAttribute('data-index', this.optionElements.length - 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

any chance you'd be willing to do a PR that removes all this "registerElement" stuff? it's very side-effect heavy and causes double (or more!) renders

Copy link
Collaborator

@NullVoxPopuli NullVoxPopuli left a comment

Choose a reason for hiding this comment

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

Changes look good / targeted to me -- at least, inline with the existing conventions of this component.

If you have time though, it'd be well worth while to modernize / reduce re-renders of the components / back-and-forth reference passing -- but that's totally out of scope for this PR. <3

Thanks!


this.scrollIntoView(optionElement);
}
}

if (!this.selectedOptionIndex) {
scheduleOnce('afterRender', this, this.setDefaultActiveOption);
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we avoid hacking runloop usage?

runloop is kinda anti-patterny and causes performance problems

@miguelcobain
Copy link
Author

A couple more changes that this PR makes:

  • we were not setting aria-selected="false" on unselected options for listbox and combox (this differs from headlessui). This was fixed for listbox and combobox.
  • when we used assertListboxOption({ selected: false }, we were not asserting anything with regards to the selected state of the option (neither the absence of aria-selected or the presence of aria-selected="false). Not we're testing that the option has aria-selected="false". This was fixed for listbox and combobox.
  • tabindex should only be -1 if the option isn't disabled. This was fixed for listbox and combobox.

@far-fetched
Copy link
Contributor

Hey @miguelcobain 👋
I just want to let you know that, I am just in the process of simplification active / selected *guid usage in <Listbox/> component. As you already noticed (and changed!) in this PR selectedOptionGuid is not necessary to be kept in parent component, similar story is with activeOptionGuid. I think my PR will simplify a lot this one – as no need to juggle with selectedOptionIndexes.

@barryofguilder
Copy link

Is there anything that needs to be done on this still or is it something that can be merged? I'm in need of multi-select support for the listbox and was going to fork this repo to get it. But I would love for this to actually be merged and released.

@barryofguilder
Copy link

I would really love for this to get merged as I have a fork of this addon just for this PR. Is there any reason this can't be merged? Does it need updates before it can?

@barryofguilder
Copy link

@NullVoxPopuli Is this something that can be merged?

@NullVoxPopuli
Copy link
Collaborator

There are conflicts, I'd say it's up to @GavinJoyce and @miguelcobain

Personally, my efforts are focused on not mimicking tailwind's patterns over here:

https://ember-primitives.pages.dev/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants