select2-bootstrap4-theme
Select2 v4 theme for Bootstrap4 (Compatible to boostrap 4.0.0+)
Live demo
Installation
CDN
<link rel="stylesheet" href="/path/to/select2.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ttskch/[email protected]/dist/select2-bootstrap4.min.css">
Manually
# npm
$ npm install @ttskch/select2-bootstrap4-theme
# yarn
$ yarn add @ttskch/select2-bootstrap4-theme
# composer
$ composer require ttskch/select2-bootstrap4-theme
<link rel="stylesheet" href="/path/to/select2.css">
<link rel="stylesheet" href="/path/to/select2-bootstrap4.min.css">
Usage
$('select').select2({
theme: 'bootstrap4',
});
Getting involved
- Fix src/_layout.scss, src/_single.scss or src/_multiple.scss
- Do
npm run build:both
- Send me a Pull Request
You can use docs dir for your development.
- Do
npm run prepare
(this creates symlink todist/select2-bootstrap4.css
ontodocs
) - Serve
docs
with your local web server (e.g.php -S localhost:8888 -t docs
) - Do
npm run watch
- Tweak scss and browse demo page on your browser
Improve style
Contains changes (some are opinionated) for better integration with Bootstrap 4
Add stylelint
Move layout to its own partial
Allow users to customize individual components or to use just one of them (e.g., "single" and "layout" when "multiple" is not needed)
Improve single component
Improve multiple component
Improve layout partial
Fix cursor on disabled elements
Reproducible with Chrome 88 on macOS
Before
After
Bootstrap variable file should not be introduced in layout.css
If I use gulp-sass instead of sass-loader to compile SCSS source code, I will not be able to proceed.
I think it is better to add in webpack.config.js:
Clear button x is not centered.
Styling of dropdown icon does not match BS4 default
The icon is a down triangle instead of a down chevron... I tweaked your demo page using the browser console to show the problem: https://jsfiddle.net/t2prb6ds/
Use custom-select-% variable instead of input
is there a reason why this package uses the input field variable instead of the
custom-select-%
variables?https://github.com/twbs/bootstrap/blob/7a6da5e3e7ad7c749dde806546a35d4d4259d965/scss/_variables.scss#L575
I had a custom drop-down indicator on my normal select fields but when I installed this package, I lost that customization. Looking through your source code, it doesnt look like any of these variables are used.
Is there a particular reason for this?
Get the primary theme colour properly
Using the bootstrap function to get the theme colour means that the source can be used by people who have overridden the primary theme colour by setting it in
$theme-colours
as per bootstrap docshttps://getbootstrap.com/docs/4.5/getting-started/theming/#modify-map
Fixes #46
Code proposal for "border-radius"
If in the Bootstrap variable file we disable the rounded border, the theme does not reflect this option. https://github.com/ttskch/select2-bootstrap4-theme/issues/38#issue-509434475
Prepend multiselect breaks when you go onto a second line.
As seen in the image below when you have a multi select and a prepend, if your selects go onto a second line it causes the entire box to drop onto the next line instead of growing on the same line.
Match style of text input box a bit more
The unrelated height
calc
changes are due to https://github.com/twbs/bootstrap/commit/51375abca5769682f1d27de2e29e6e9f15ec7314#diff-d8ee409a461718bfb6240710c8c73382L491Fix form-control layout
The input field does not use the full size of the fieldset, with this change it fits the column fully. Also the select2 option "width" must be set to "style", otherwise the calculation makes it go beyond the fieldset.
BS Theme not working on js-example-tags
The theme doesn't seem to be working on the tags element. This is the code I am using below. But the image shows the differance between the Select2 field and the BS4 field
Deprecation warnings
The sass builder gives deprecation warnings when building this package. I fixed these warnings, but node-sass doesn't compile the code anymore. Since node-sass is deprecated (https://www.npmjs.com/package/node-sass), I swapped it out for sass. This changed a lot of lines in the dist directory, but these are all just curly brackets that are placed on it's own line.
Deprecation Warnings
When running
npm build
on a repository that depends on this, I get a lot of deprecation warnings due to SCSS that does math without encompassing it in thecalc()
function. Is a fix for this in the works? If not I would be happy to work on one and make a PR when I have the time, just let me know! :)Fix search field background color.
Fix select2-search__field background color by changing to transparent like default and classic themes.
Currently when the Bootstrap's $input-bg variable isn't white, the search field still white and looks like this:
Invalid layout on multiple select and input-group
When using select2 with multi select, input-group and the total length of items is smaller than the form group, the prepend and append groups are aligned correctly:
But if more items are added, the prepend and append groups move to a new line:
Select2 Multiple Tagging Support
Is this theme support for select2 multiple tagging?
The default style is like this:
But when I applied the theme:
The style is ugly:
Is there any instruction for this or it's not available?