-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[Admin][UI] New select component #6190
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
Conversation
f41962e to
a4f6329
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6190 +/- ##
==========================================
+ Coverage 88.72% 88.78% +0.06%
==========================================
Files 838 839 +1
Lines 18193 18215 +22
==========================================
+ Hits 16142 16173 +31
+ Misses 2051 2042 -9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
tvdeyen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I like us to include third party libraries like that. But I would like us to get rid of Stimulus as well in the select component. Can you try to extract the validation logic into a reusable es module?
admin/app/javascript/solidus_admin/web_components/tom_select.js
Outdated
Show resolved
Hide resolved
|
|
||
| pin "tom-select", to: "https://ga.jspm.io/npm:[email protected]/dist/esm/tom-select.complete.js" | ||
| pin "@orchidjs/sifter", to: "https://ga.jspm.io/npm:@orchidjs/[email protected]/dist/esm/sifter.js" | ||
| pin "@orchidjs/unicode-variants", to: "https://ga.jspm.io/npm:@orchidjs/[email protected]/dist/esm/index.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
urgh. just realized that we use CDNs for third party libraries. That is something we want to address in the future and download them instead. This is a performance nightmare and a potential GDPR violation.
admin/app/components/solidus_admin/ui/forms/select/component.rb
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. Works great. We need to add support for Safari and I have a weird behaviour with single selects.
After selecting a value there still is a carret
And I can type ahead
Not sure if this is a expected behaviour for tomselect and there are valid reasons (a11y) for that, but still it is very uncommon. Maybe this can be disabled?
|
thanks @tvdeyen! re: single select caret, it's indeed a default Tomselect behaviour and I agree it does not feel right. A workaround for that could be using a built-in plugin for search input being placed inside a dropdown for single selects: We could customize it further, e.g. have search input only when there are more than 10 options in the dropdown (really does not make sense to have it for 2-3 options, only taking away the space). And for multiple selects I'd still keep the search as it is now, it feels natural. Let me know what you think! |
848a8b0 to
1c43103
Compare
|
@tvdeyen I ended up downloading the shim and continue using "is" attribute. The caret and type ahead in single selects is also fixed in a way that the input will become non-visible to the user, but if they try to type the options will still be filtered (kind of how the common select elements work) |
tvdeyen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@tvdeyen oh yeah! i thought i added it but apparently it's in another PR I've been working on. will fix! |
|
hi @tvdeyen, so it appeared that removing |
I feared that that will be the problem and I don't like that solution either. It will fall apart very fast (selects on the bottom of the screen need to be aligned to the bottom of the container. etc. pp.) This can be very cumbersome to maintain. If there is no simpler solution (or plugin) I think we should live with that fact. That's due to the fact that we use modals now. I like modals, but they come with their own bag of problems. We can also decide to not use a modal in that example (adding store credit) |
|
@tvdeyen agreed, but can you please clarify what you mean by:
The simplest I can do is to remove overflow-auto from inner container, so that instead of this |
d28ab12 to
c3f7c7c
Compare
|
@tvdeyen could you please have a look when you have time, I have a couple of PRs dependent on this one, would be very helpful to move this forward 🙏 |
Uses Tom Select (https://tom-select.js.org/).
This allows to reuse it in the new select component. Changes value name to be more reflective of what it stores.
Changed "Store Credit ..." to "Store credit ..." to match the lowercase second-word style used in other places.
Also removes all logic regarding rendering a select field from "ui/forms/input" component as not relevant. Adds a test helper `tomselect` for feature tests.
Uses tailwind's `peer-invalid` state modifier to conditionally show/hide error message.
In compliance with commit 1ff04b2
Due to Safari not supporting customized builtins (is="" attribute) (https://bugs.webkit.org/show_bug.cgi?id=182671) use a polyfill to provide this functionality in Safari.
This change brings a behaviour similar to the one that common HTML selects have, on top of some of TomSelect niceties. By default, TomSelect would include a search input in single select mode, even when there is an option selected, which is uncommon. So instead, we keep search box visible only when there is nothing selected. As soon as user selects an option, select box gains "opacity-0" and therefore hides the confusing search box effects (caret and ability to type ahead). However, since a usual HTML select responds to user's typing by highlighting matched option (if any), we can replicate this logic because technically the input is not gone, and it still responds to user input. If user types while the select is focused, the options will be filtered and highlight will be applied (TomSelect defaults), however if filter search returns 0 options - we reset the search term to empty string and options displayed to show full list again.
c3f7c7c to
252788d
Compare
|
@tvdeyen done! |
tvdeyen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works very well now! Thanks






Summary
Adds a new select component in "ui/forms/select", using Tom Select under the hood.
Tom Select integration done with a web component, extending an
HTMLSelectElement.Reused styles from "ui/dropdown" for options dropdown, and from "ui/badge" for multiple options selected.
Other changes:
Demo:
Component overview
Screen.Recording.2025-03-14.at.19.05.06.mov
Address component using new select
Screen.Recording.2025-03-14.at.19.08.52.mov
Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs: