UNPKG

@gpaol/bootstrap-multiselect

Version:

Bootstrap 5 MultiSelect component with search, filtering, grouped options, pagination, and comprehensive localization support

522 lines (431 loc) • 14 kB
/*! * Bootstrap MultiSelect - CSS Styles v1.2.0 * * Additional styles and enhancements for the Bootstrap MultiSelect plugin * * Authors: Paolo Gaetano * Copyright (c) 2026 Paolo Gaetano * Released under the MIT license * * @requires jQuery >= 3.6 * @requires Bootstrap >= 5.0 */ /* ========================================================================== Container Styles ========================================================================== */ .bs-multiselect-container { position: relative; display: inline-block; } .bs-multiselect-container .dropdown-toggle { text-overflow: ellipsis; overflow: hidden; white-space: nowrap; } .bs-multiselect-container .dropdown-toggle::after { flex-shrink: 0; } /* ========================================================================== Button Styles ========================================================================== */ .bs-multiselect-placeholder { flex-grow: 1; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; } .bs-multiselect-badge { flex-shrink: 0; border-radius: 10px; padding: 0.25em 0.5em; font-size: 0.75em; font-weight: 600; line-height: 1; } /* ========================================================================== Dropdown Menu Styles ========================================================================== */ .bs-multiselect-container .dropdown-menu { padding: 0; box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15); border: 1px solid rgba(0, 0, 0, 0.15); background-color: #ffffff !important; } /* jQuery Validation - Show green border for valid fields */ form .bs-multiselect-container > .is-valid { border-color: #198754; padding-right: calc(1.5em + 0.75rem); background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23198754' d='M2.3 6.73.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e") !important; background-repeat: no-repeat; background-position: right calc(0.375em + 0.1875rem) center; background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem); } form .bs-multiselect-container > .is-valid:focus { border-color: #198754; box-shadow: 0 0 0 0.25rem rgba(25, 135, 84, 0.25); } /* ========================================================================== Search Input Styles ========================================================================== */ .bs-multiselect-search { border: 1px solid #dee2e6; border-radius: 0.25rem; padding: 0.375rem 0.75rem; font-size: 0.875rem; transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; } .bs-multiselect-search:focus { border-color: #86b7fe; outline: 0; box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25); } /* ========================================================================== Options Styles ========================================================================== */ .bs-multiselect-options { background-color: #ffffff; } .bs-multiselect-option { padding: 0.5rem 0.75rem; cursor: pointer; transition: background-color 0.15s ease-in-out; user-select: none; background-color: #ffffff !important; display: flex; align-items: center; gap: 0.5rem; } .bs-multiselect-option:hover { background-color: #f8f9fa !important; } .bs-multiselect-option.disabled, .bs-multiselect-option:has(.form-check-input:disabled) { opacity: 0.5; cursor: not-allowed; } .bs-multiselect-option.disabled:hover, .bs-multiselect-option:has(.form-check-input:disabled):hover { background-color: #ffffff !important; } .bs-multiselect-option .form-check { display: flex; align-items: center; gap: 0.5rem; width: 100%; margin-bottom: 0; padding-left: 0; } .bs-multiselect-option .form-check-input { cursor: pointer; margin-top: 0; margin-left: 0; flex-shrink: 0; float: none; } .bs-multiselect-option .form-check-label { cursor: pointer; margin-bottom: 0; padding-left: 0; color: #212529 !important; flex-grow: 1; } .bs-multiselect-option .form-check-input:disabled ~ .form-check-label { opacity: 0.5; cursor: not-allowed; } /* ========================================================================== OptGroup Styles ========================================================================== */ .bs-multiselect-optgroup { margin-bottom: 0.5rem; } .bs-multiselect-optgroup:last-child { margin-bottom: 0; } .bs-multiselect-optgroup > div:first-child { font-weight: 600; color: #6c757d; font-size: 0.875rem; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 0.25rem; } /* ========================================================================== Action Buttons Styles ========================================================================== */ .bs-multiselect-select-all, .bs-multiselect-deselect-all { font-size: 0.875rem; padding: 0.375rem 0.75rem; transition: all 0.15s ease-in-out; } .bs-multiselect-select-all:hover, .bs-multiselect-deselect-all:hover { transform: translateY(-1px); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } .bs-multiselect-select-all:disabled, .bs-multiselect-select-all.disabled, .bs-multiselect-deselect-all:disabled, .bs-multiselect-deselect-all.disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; } .bs-multiselect-select-all:disabled:hover, .bs-multiselect-select-all.disabled:hover, .bs-multiselect-deselect-all:disabled:hover, .bs-multiselect-deselect-all.disabled:hover { transform: none; box-shadow: none; } /* ========================================================================== No Results Message ========================================================================== */ .bs-multiselect-no-results { padding: 1rem; color: #6c757d; font-style: italic; } /* ========================================================================== Pagination Controls ========================================================================== */ .bs-multiselect-pagination { padding: 0.5rem 0; margin: 0; border-top: 1px solid #dee2e6; background-color: #f8f9fa; flex-shrink: 0; /* Prevent pagination from being compressed */ } /* Top pagination */ .bs-multiselect-pagination.pagination-top { border-top: none; border-bottom: 1px solid #dee2e6; } /* Bottom pagination */ .bs-multiselect-pagination.pagination-bottom { border-top: 1px solid #dee2e6; border-bottom: none; } /* When pagination is on both sides */ .bs-multiselect-pagination.pagination-top + .bs-multiselect-options { border-top: 1px solid #dee2e6; } .bs-multiselect-prev-page, .bs-multiselect-next-page { font-size: 0.8125rem; padding: 0.25rem 0.75rem; transition: all 0.15s ease-in-out; min-width: 80px; } .bs-multiselect-prev-page:hover:not(:disabled), .bs-multiselect-next-page:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } .bs-multiselect-prev-page:disabled, .bs-multiselect-next-page:disabled { opacity: 0.5; cursor: not-allowed; } .bs-multiselect-page-info { font-size: 0.875rem; font-weight: 500; color: #495057; padding: 0 0.5rem; white-space: nowrap; } /* ========================================================================== Loading State ========================================================================== */ .bs-multiselect-loading { text-align: center; padding: 1rem; color: #6c757d; } .bs-multiselect-loading::after { content: ''; display: inline-block; width: 1rem; height: 1rem; border: 2px solid #6c757d; border-radius: 50%; border-top-color: transparent; animation: bs-multiselect-spin 0.6s linear infinite; margin-left: 0.5rem; } @keyframes bs-multiselect-spin { to { transform: rotate(360deg); } } /* ========================================================================== Disabled State ========================================================================== */ .bs-multiselect-container .dropdown-toggle:disabled { opacity: 0.65; cursor: not-allowed; } /* ========================================================================== Responsive Styles ========================================================================== */ @media (max-width: 576px) { .bs-multiselect-container .dropdown-menu { max-width: 100vw; max-height: 70vh !important; } .bs-multiselect-options { max-height: 50vh; } .bs-multiselect-select-all, .bs-multiselect-deselect-all { font-size: 0.8125rem; padding: 0.25rem 0.5rem; } } /* ========================================================================== Dark Mode Support - DISABLED (using light theme only) ========================================================================== */ /* @media (prefers-color-scheme: dark) { .bs-multiselect-container .dropdown-menu { background-color: #212529; border-color: #495057; } .bs-multiselect-option { background-color: #212529; color: #ffffff; } .bs-multiselect-option:hover { background-color: #343a40; } .bs-multiselect-option .form-check-label { color: #ffffff; } .bs-multiselect-search { background-color: #212529; border-color: #495057; color: #fff; } .bs-multiselect-search:focus { border-color: #6ea8fe; box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25); } .bs-multiselect-no-results, .bs-multiselect-loading { color: #adb5bd; } } */ /* Dark mode via Bootstrap data attribute - DISABLED */ /* [data-bs-theme="dark"] .bs-multiselect-container .dropdown-menu { background-color: #212529; border-color: #495057; } [data-bs-theme="dark"] .bs-multiselect-option { background-color: #212529; color: #ffffff; } [data-bs-theme="dark"] .bs-multiselect-option:hover { background-color: #343a40; } [data-bs-theme="dark"] .bs-multiselect-option .form-check-label { color: #ffffff; } [data-bs-theme="dark"] .bs-multiselect-search { background-color: #212529; border-color: #495057; color: #fff; } [data-bs-theme="dark"] .bs-multiselect-search:focus { border-color: #6ea8fe; box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25); } [data-bs-theme="dark"] .bs-multiselect-no-results, [data-bs-theme="dark"] .bs-multiselect-loading { color: #adb5bd; } */ /* ========================================================================== Theme Variants ========================================================================== */ /* Primary Theme */ .bs-multiselect-container.theme-primary .bs-multiselect-badge { background-color: #0d6efd !important; } /* Secondary Theme */ .bs-multiselect-container.theme-secondary .bs-multiselect-badge { background-color: #6c757d !important; } /* Success Theme */ .bs-multiselect-container.theme-success .bs-multiselect-badge { background-color: #198754 !important; } /* Danger Theme */ .bs-multiselect-container.theme-danger .bs-multiselect-badge { background-color: #dc3545 !important; } /* Warning Theme */ .bs-multiselect-container.theme-warning .bs-multiselect-badge { background-color: #ffc107 !important; color: #000 !important; } /* Info Theme */ .bs-multiselect-container.theme-info .bs-multiselect-badge { background-color: #0dcaf0 !important; color: #000 !important; } /* Light Theme */ .bs-multiselect-container.theme-light .bs-multiselect-badge { background-color: #f8f9fa !important; color: #000 !important; } /* Dark Theme */ .bs-multiselect-container.theme-dark .bs-multiselect-badge { background-color: #212529 !important; } /* ========================================================================== Animation Utilities ========================================================================== */ .bs-multiselect-fade-in { animation: bs-multiselect-fadeIn 0.2s ease-in; } @keyframes bs-multiselect-fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } } /* ========================================================================== Custom Checkbox Styles (Optional Enhancement) ========================================================================== */ .bs-multiselect-option .form-check-input:checked { background-color: #0d6efd; border-color: #0d6efd; } .bs-multiselect-option .form-check-input:focus { border-color: #86b7fe; outline: 0; box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25); } /* ========================================================================== Compact Mode ========================================================================== */ .bs-multiselect-compact .bs-multiselect-option { padding: 0.25rem 0.5rem; font-size: 0.875rem; } .bs-multiselect-compact .bs-multiselect-select-all, .bs-multiselect-compact .bs-multiselect-deselect-all { font-size: 0.8125rem; padding: 0.25rem 0.5rem; } .bs-multiselect-compact .bs-multiselect-search { font-size: 0.8125rem; padding: 0.25rem 0.5rem; }