Skip to content

Commit

Permalink
checkbox_options: improve layout of options using flexbox
Browse files Browse the repository at this point in the history
wraps checkbox and option in a container and adds display:flex to option.
this prevents weird option text wrapping in compact selects.
  • Loading branch information
glaszig committed Oct 26, 2023
1 parent 16f4de2 commit 243d551
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
21 changes: 14 additions & 7 deletions src/plugins/checkbox_options/plugin.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
.plugin-checkbox_options:not(.rtl) {
.option input {
margin-right: 0.5rem;
.plugin-checkbox_options {
.option {
display: flex;
align-items: center;
}

&:not(.rtl) {
.option input {
margin-right: 0.5rem;
}
}
}

.plugin-checkbox_options.rtl {
.option input {
margin-left: 0.5rem;
&.rtl {
.option input {
margin-left: 0.5rem;
}
}
}
11 changes: 10 additions & 1 deletion src/plugins/checkbox_options/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import { preventDefault, hash_key } from '../../utils';
import { getDom } from '../../vanilla';
import { CBOptions } from './types';

function wrap(nodes:Array<HTMLElement>) {
const wrapper = document.createElement('div')
nodes.forEach((n:HTMLElement) => wrapper.appendChild(n))

return wrapper
}

export default function(this:TomSelect, userOptions:CBOptions) {
var self = this;
Expand Down Expand Up @@ -85,7 +91,10 @@ export default function(this:TomSelect, userOptions:CBOptions) {

UpdateChecked(checkbox, !!(hashed && self.items.indexOf(hashed) > -1) );

rendered.prepend(checkbox);
const nodes = Array.prototype.slice.call(rendered.childNodes)
rendered.appendChild(wrap(nodes));
rendered.prepend(wrap([checkbox]));

return rendered;
};
});
Expand Down

0 comments on commit 243d551

Please sign in to comment.