Skip to content
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
40 changes: 40 additions & 0 deletions docs/content/examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description: Live bootstrap-select examples hosted by the Docusaurus docs site.
---

import LiveExample from '@site/src/components/LiveExample';
import Link from '@docusaurus/Link';

# Basic examples

Expand All @@ -20,6 +21,7 @@ The main examples now live directly on this docs page so they inherit the docs t
- [Search and multi-select workflows](#search-and-multi-select-workflows)
- [Selection text and summaries](#selection-text-and-summaries)
- [Styling and layout](#styling-and-layout)
- [Native Bootstrap comparison](#native-bootstrap-comparison)
- [Rich option content](#rich-option-content)
- [Menu behavior](#menu-behavior)
- [Disabled states](#disabled-states)
Expand Down Expand Up @@ -544,6 +546,44 @@ The supported values are:

---

### Native Bootstrap comparison

`bootstrap-select` is styled to mirror a native Bootstrap 5.3 `.form-select`: the
placeholder color, chevron icon, disabled options, optgroup headers, and selection ticks
all resolve from Bootstrap CSS variables, so they follow your theme automatically. Toggle
this site's light/dark switch to see both controls stay in sync.

<LiveExample
html={String.raw` <div class="row g-3">
<div class="col-sm-6">
<p class="mb-1 text-body-secondary">Native <code>.form-select</code></p>
<select class="form-select" aria-label="Native select">
<option value="" selected disabled>Choose a condiment</option>
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
</div>
<div class="col-sm-6">
<p class="mb-1 text-body-secondary">bootstrap-select</p>
<select class="selectpicker form-control" placeholder="Choose a condiment">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
</div>
</div>`}
/>

For a full side-by-side reference (placeholders, optgroups, disabled options, dividers, and
selection checkmarks) with its own color-mode selector, open the standalone page:

<p>
<Link to="pathname:///examples/comparison.html" target="_blank" rel="noopener noreferrer">
Open the native vs. bootstrap-select comparison ↗
</Link>
</p>

### Button classes

You can set the button classes via the `data-style` attribute:
Expand Down
7 changes: 7 additions & 0 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ const config = {
label: 'Examples',
position: 'left'
},
{
to: 'pathname:///examples/comparison.html',
label: 'Comparison',
position: 'left',
target: '_blank',
rel: 'noopener noreferrer'
},
{
type: 'docsVersionDropdown',
position: 'right',
Expand Down
123 changes: 123 additions & 0 deletions docs/static/examples/comparison.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>bootstrap-select vs native Bootstrap select</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="../dist/css/bootstrap-select.min.css">
<style>
.swatch-label { font-size: .875rem; letter-spacing: .02em; }
</style>
</head>
<body class="p-4">
<main class="container" style="max-width: 720px;">
<h1 class="h4 mb-1">Native Bootstrap select vs. bootstrap-select</h1>
<p class="text-body-secondary">
Both controls share the same placeholder color (<code>--bs-secondary-color</code>) and the
same Bootstrap&nbsp;5.3 chevron. Use the color mode selector to confirm they stay in sync.
</p>

<div class="row align-items-end g-3 mb-3">
<div class="col-auto">
<label for="color-mode" class="form-label swatch-label text-uppercase text-body-secondary mb-1">Color mode</label>
<select class="form-select form-select-sm" id="color-mode" aria-label="Color mode selector" style="width: auto;">
<option value="light" selected>Light</option>
<option value="dark">Dark</option>
<option value="auto">Auto (system)</option>
</select>
</div>
</div>

<div class="row g-4">
<div class="col-md-6">
<p class="swatch-label text-uppercase text-body-secondary mb-1">Native <code>.form-select</code></p>
<select class="form-select" aria-label="Native select">
<option value="" selected disabled>Choose a condiment</option>
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
</div>

<div class="col-md-6">
<p class="swatch-label text-uppercase text-body-secondary mb-1">bootstrap-select</p>
<select class="selectpicker form-control" placeholder="Choose a condiment">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
</div>
</div>

<hr class="my-4">

<p class="swatch-label text-uppercase text-body-secondary mb-1">Groups, disabled options &amp; dividers</p>
<div class="row g-4">
<div class="col-md-6">
<p class="small text-body-secondary mb-1">Native reference</p>
<select class="form-select" size="8" aria-label="Native grouped select">
<optgroup label="Condiments">
<option>Mustard</option>
<option disabled>Ketchup (out of stock)</option>
<option>Relish</option>
</optgroup>
<optgroup label="Sauces">
<option>Barbecue</option>
<option>Sriracha</option>
</optgroup>
</select>
</div>
<div class="col-md-6">
<p class="small text-body-secondary mb-1">bootstrap-select</p>
<select class="selectpicker form-control" id="grouped" data-show-tick="true">
<optgroup label="Condiments">
<option>Mustard</option>
<option disabled>Ketchup (out of stock)</option>
<option selected>Relish</option>
</optgroup>
<optgroup label="Sauces">
<option>Barbecue</option>
<option>Sriracha</option>
</optgroup>
</select>
</div>
</div>

<hr class="my-4">

<p class="swatch-label text-uppercase text-body-secondary mb-1">bootstrap-select, selection with checkmark</p>
<select class="selectpicker form-control" data-show-tick="true">
<option>Mustard</option>
<option selected>Ketchup</option>
<option>Relish</option>
</select>
</main>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js"></script>
<script src="../dist/js/bootstrap-select.min.js"></script>
<script>
(function () {
var root = document.documentElement;
var selector = document.getElementById('color-mode');
var media = window.matchMedia('(prefers-color-scheme: dark)');

function resolvedTheme(mode) {
return mode === 'auto' ? (media.matches ? 'dark' : 'light') : mode;
}

function applyTheme() {
root.setAttribute('data-bs-theme', resolvedTheme(selector.value));
}

selector.addEventListener('change', applyTheme);
// Keep "Auto" in sync when the OS theme changes while selected.
media.addEventListener('change', function () {
if (selector.value === 'auto') applyTheme();
});

applyTheme();
})();
</script>
</body>
</html>
1 change: 0 additions & 1 deletion js/bootstrap-select.render.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@

remove.className = 'bs-selected-item-remove';
remove.setAttribute('aria-hidden', 'true');
remove.textContent = '\u00d7';

selectedTag.appendChild(content);
selectedTag.appendChild(remove);
Expand Down
Loading