From 2953301b088a439f4fdff21832f449dc5d610ad5 Mon Sep 17 00:00:00 2001 From: Pavak Paul Date: Tue, 25 Jul 2023 18:49:12 +0530 Subject: [PATCH] hide disabled selec2 filter options --- .../README.md | 21 +++++++++++++++++++ .../hide-globally-style.css | 4 ++++ .../hide-specific-filters-style.css | 5 +++++ 3 files changed, 30 insertions(+) create mode 100644 hide-disabled-filter-options-for-select2/README.md create mode 100644 hide-disabled-filter-options-for-select2/hide-globally-style.css create mode 100644 hide-disabled-filter-options-for-select2/hide-specific-filters-style.css diff --git a/hide-disabled-filter-options-for-select2/README.md b/hide-disabled-filter-options-for-select2/README.md new file mode 100644 index 0000000..b456a18 --- /dev/null +++ b/hide-disabled-filter-options-for-select2/README.md @@ -0,0 +1,21 @@ +By default, Select2 doesn't hide any empty filter options. Instead, it makes them disabled which prevents clicking them. This works well when you only have a few filter options but for large filter options, it might be better to hide them instead. + +### If you want to hide the disabled filter options globally, use [this CSS](hide-globally-style.css): + +```css +/* Hide disabled (empty) options for select2 globally */ +.select2-results__option--disabled { + display: none; +} +``` + +### If you want to hide the disabled filter options for particular filter or filter item, use [this CSS](hide-specific-filters-style.css): + +```css +/* Hide disabled (empty) options for select2 in specific filters only */ +/* Add the class hide-empty-select2-options to a Filter Posts module or to a particular Filter Item to hide empty options for that particular Filter Posts module or Filter item only */ +.hide-empty-select2-options .select2-results__option--disabled { + display: none; +} +``` +Add this CSS class to the Filter Posts module or the Filter Item: `hide-empty-select2-options`. \ No newline at end of file diff --git a/hide-disabled-filter-options-for-select2/hide-globally-style.css b/hide-disabled-filter-options-for-select2/hide-globally-style.css new file mode 100644 index 0000000..d649847 --- /dev/null +++ b/hide-disabled-filter-options-for-select2/hide-globally-style.css @@ -0,0 +1,4 @@ +/* Hide disabled (empty) options for select2 globally */ +.select2-results__option--disabled { + display: none; +} \ No newline at end of file diff --git a/hide-disabled-filter-options-for-select2/hide-specific-filters-style.css b/hide-disabled-filter-options-for-select2/hide-specific-filters-style.css new file mode 100644 index 0000000..5270afd --- /dev/null +++ b/hide-disabled-filter-options-for-select2/hide-specific-filters-style.css @@ -0,0 +1,5 @@ +/* Hide disabled (empty) options for select2 in specific filters only */ +/* Add the class hide-empty-select2-options to a Filter Posts module or to a particular Filter Item to hide empty options for that particular Filter Posts module or Filter item only */ +.hide-empty-select2-options .select2-results__option--disabled { + display: none; +} \ No newline at end of file