]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Bring back btn-check for now, but move to button stylesheet
authorMark Otto <markdotto@gmail.com>
Wed, 24 Sep 2025 05:30:21 +0000 (22:30 -0700)
committerMark Otto <markdotto@gmail.com>
Wed, 24 Sep 2025 06:20:58 +0000 (23:20 -0700)
scss/buttons/_button.scss
site/src/content/docs/components/button-group.mdx
site/src/content/docs/components/buttons.mdx
site/src/content/docs/customize/overview.mdx

index 2bbe49459f4bb0e45eb693ee4f780253f23405fa..c5f2da559754aee3d6a13f238057d836ad0696f8 100644 (file)
   .btn-sm {
     @include button-size($btn-padding-y-sm, $btn-padding-x-sm, $btn-font-size-sm, $btn-border-radius-sm);
   }
+
+  .btn-check {
+    position: absolute;
+    clip: rect(0, 0, 0, 0);
+    pointer-events: none;
+
+    &[disabled],
+    &:disabled {
+      + .btn {
+        pointer-events: none;
+        filter: none;
+        opacity: .65;
+      }
+    }
+  }
 }
index 5e59feb5b61697fe224ddbd1b91217d26d2b0f6d..34a3055ad50f0ad0ed5dd2704e9906d4c828c45d 100644 (file)
@@ -44,7 +44,7 @@ These classes can also be added to groups of links, as an alternative to the [`.
 
 ## Checkbox and radio button groups
 
-Combine button-like checkbox and radio [toggle buttons]([[docsref:/forms/checks-radios]]) into a seamless looking button group.
+Combine button-like checkbox and radio toggle buttons into a seamless looking button group.
 
 <Example code={`<div class="btn-group" role="group" aria-label="Basic checkbox toggle button group">
     <input type="checkbox" class="btn-check" id="btncheck1" autocomplete="off">
index 56f4abffa955ed5a28872e16ac8dd3f066646797..5fc49bda8390e8b6d1dc57be1643026002799bad 100644 (file)
@@ -126,12 +126,83 @@ Additional utilities can be used to adjust the alignment of buttons when horizon
     <button class="btn btn-primary" type="button">Button</button>
   </div>`} />
 
+## Toggle buttons
+
+Create button-like checkboxes and radio buttons by using `.btn` styles rather than `.form-check-label` on the `<label>` elements. These toggle buttons can further be grouped in a [button group]([[docsref:/components/button-group]]) if needed.
+
+### Checkbox toggle buttons
+
+<Example code={`<input type="checkbox" class="btn-check" id="btn-check" autocomplete="off">
+<label class="btn btn-primary" for="btn-check">Single toggle</label>
+
+<input type="checkbox" class="btn-check" id="btn-check-2" checked autocomplete="off">
+<label class="btn btn-primary" for="btn-check-2">Checked</label>
+
+<input type="checkbox" class="btn-check" id="btn-check-3" autocomplete="off" disabled>
+<label class="btn btn-primary" for="btn-check-3">Disabled</label>`} />
+
+<Example code={`<input type="checkbox" class="btn-check" id="btn-check-4" autocomplete="off">
+<label class="btn" for="btn-check-4">Single toggle</label>
+
+<input type="checkbox" class="btn-check" id="btn-check-5" checked autocomplete="off">
+<label class="btn" for="btn-check-5">Checked</label>
+
+<input type="checkbox" class="btn-check" id="btn-check-6" autocomplete="off" disabled>
+<label class="btn" for="btn-check-6">Disabled</label>`} />
+
+<Callout>
+Visually, these checkbox toggle buttons are identical to the [button plugin toggle buttons]([[docsref:/components/buttons#button-plugin]]). However, they are conveyed differently by assistive technologies: the checkbox toggles will be announced by screen readers as “checked“/“not checked“ (since, despite their appearance, they are fundamentally still checkboxes), whereas the button plugin toggle buttons will be announced as “button“/“button pressed“. The choice between these two approaches will depend on the type of toggle you are creating, and whether or not the toggle will make sense to users when announced as a checkbox or as an actual button.
+</Callout>
+
+### Radio toggle buttons
+
+<Example code={`<input type="radio" class="btn-check" name="options" id="option1" autocomplete="off" checked>
+<label class="btn btn-secondary" for="option1">Checked</label>
+
+<input type="radio" class="btn-check" name="options" id="option2" autocomplete="off">
+<label class="btn btn-secondary" for="option2">Radio</label>
+
+<input type="radio" class="btn-check" name="options" id="option3" autocomplete="off" disabled>
+<label class="btn btn-secondary" for="option3">Disabled</label>
+
+<input type="radio" class="btn-check" name="options" id="option4" autocomplete="off">
+<label class="btn btn-secondary" for="option4">Radio</label>`} />
+
+<Example code={`<input type="radio" class="btn-check" name="options-base" id="option5" autocomplete="off" checked>
+<label class="btn" for="option5">Checked</label>
+
+<input type="radio" class="btn-check" name="options-base" id="option6" autocomplete="off">
+<label class="btn" for="option6">Radio</label>
+
+<input type="radio" class="btn-check" name="options-base" id="option7" autocomplete="off" disabled>
+<label class="btn" for="option7">Disabled</label>
+
+<input type="radio" class="btn-check" name="options-base" id="option8" autocomplete="off">
+<label class="btn" for="option8">Radio</label>`} />
+
+### Outlined styles
+
+Different variants of `.btn`, such as the various outlined styles, are supported.
+
+<Example code={`<input type="checkbox" class="btn-check" id="btn-check-outlined" autocomplete="off">
+<label class="btn btn-outline-primary" for="btn-check-outlined">Single toggle</label><br>
+
+<input type="checkbox" class="btn-check" id="btn-check-2-outlined" checked autocomplete="off">
+<label class="btn btn-outline-secondary" for="btn-check-2-outlined">Checked</label><br>
+
+<input type="radio" class="btn-check" name="options-outlined" id="success-outlined" autocomplete="off" checked>
+<label class="btn btn-outline-success" for="success-outlined">Checked success radio</label>
+
+<input type="radio" class="btn-check" name="options-outlined" id="danger-outlined" autocomplete="off">
+<label class="btn btn-outline-danger" for="danger-outlined">Danger radio</label>`} />
+
+
 ## Button plugin
 
 The button plugin allows you to create simple on/off toggle buttons.
 
 <Callout>
-Visually, these toggle buttons are identical to the [checkbox toggle buttons]([[docsref:/forms/checks-radios#checkbox-toggle-buttons]]). However, they are conveyed differently by assistive technologies: the checkbox toggles will be announced by screen readers as “checked”/“not checked” (since, despite their appearance, they are fundamentally still checkboxes), whereas these toggle buttons will be announced as “button”/“button pressed”. The choice between these two approaches will depend on the type of toggle you are creating, and whether or not the toggle will make sense to users when announced as a checkbox or as an actual button.
+Visually, these toggle buttons are identical to the [checkbox toggle buttons]([[docsref:/forms/checks]]). However, they are conveyed differently by assistive technologies: the checkbox toggles will be announced by screen readers as “checked”/“not checked” (since, despite their appearance, they are fundamentally still checkboxes), whereas these toggle buttons will be announced as “button”/“button pressed”. The choice between these two approaches will depend on the type of toggle you are creating, and whether or not the toggle will make sense to users when announced as a checkbox or as an actual button.
 </Callout>
 
 ### Toggle states
index 323e6546b4c52b6fb491c3991fee59d9edb9f991..a90cc7c9d7a3d34f072988501ae5c88dff829eac 100644 (file)
@@ -42,10 +42,7 @@ Several Bootstrap components include embedded SVGs in our CSS to style component
 - [Accordion]([[docsref:/components/accordion]])
 - [Carousel controls]([[docsref:/components/carousel#with-controls]])
 - [Close button]([[docsref:/components/close-button]]) (used in alerts and modals)
-- [Form checkboxes and radio buttons]([[docsref:/forms/checks-radios]])
-- [Form switches]([[docsref:/forms/checks-radios#switches]])
 - [Form validation icons]([[docsref:/forms/validation#server-side]])
 - [Navbar toggle buttons]([[docsref:/components/navbar#responsive-behaviors]])
-{/* - [Select menus]([[docsref:/forms/select]]) */}
 
 Based on [community conversation](https://github.com/twbs/bootstrap/issues/25394), some options for addressing this in your own codebase include [replacing the URLs with locally hosted assets]([[docsref:/getting-started/webpack#extracting-svg-files]]), removing the images and using inline images (not possible in all components), and modifying your CSP. Our recommendation is to carefully review your own security policies and decide on the best path forward, if necessary.