Skip to content

Commit 983f589

Browse files
authored
More button cleanup (#41968)
* Clean up button vars, docs, fix up .btn-link * more buttons docs cleanup * Remove colored links for theme utilities * Fix scssdocs * Fix broken link * Fix another link
1 parent d67059f commit 983f589

File tree

15 files changed

+73
-152
lines changed

15 files changed

+73
-152
lines changed

scss/_variables.scss

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -337,30 +337,6 @@ $mark-color: $body-color !default;
337337
$mark-bg: var(--yellow-100) !default;
338338
// scss-docs-end type-variables
339339

340-
341-
// Buttons + Forms
342-
//
343-
// Shared variables that are reassigned to `$input-` and `$btn-` specific variables.
344-
345-
// scss-docs-start input-btn-variables
346-
$input-btn-padding-y: .375rem !default;
347-
$input-btn-padding-x: .75rem !default;
348-
$input-btn-font-family: null !default;
349-
$input-btn-font-size: $font-size-base !default;
350-
$input-btn-line-height: $line-height-base !default;
351-
352-
$input-btn-padding-y-sm: .25rem !default;
353-
$input-btn-padding-x-sm: .5rem !default;
354-
$input-btn-font-size-sm: $font-size-sm !default;
355-
356-
$input-btn-padding-y-lg: .5rem !default;
357-
$input-btn-padding-x-lg: 1rem !default;
358-
$input-btn-font-size-lg: $font-size-lg !default;
359-
360-
$input-btn-border-width: var(--border-width) !default;
361-
// scss-docs-end input-btn-variables
362-
363-
364340
// Z-index master list
365341
//
366342
// Warning: Avoid customizing these values. They're used for a bird's eye view

scss/buttons/_button-group.scss

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@
1515
> [class*="btn-"] {
1616
position: relative;
1717
flex: 1 1 auto;
18+
19+
&:hover {
20+
z-index: 1;
21+
}
1822
}
1923

20-
// Bring the hover, focused, and "active" buttons to the front to overlay
21-
// the borders properly
2224
> .btn-check:has(input:checked),
23-
> .btn-check:has(input:focus),
24-
> [class*="btn-"]:hover,
25-
> [class*="btn-"]:focus,
2625
> [class*="btn-"]:active,
2726
> [class*="btn-"].active {
28-
z-index: 1;
27+
z-index: 2;
28+
}
29+
30+
> .btn-check:has(input:focus),
31+
> [class*="btn-"]:focus {
32+
z-index: 3;
2933
}
3034
}
3135

scss/buttons/_button-variables.scss

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,25 @@
77

88
// scss-docs-start btn-variables
99
$btn-color: var(--fg-body) !default;
10-
$btn-padding-y: $input-btn-padding-y !default;
11-
$btn-padding-x: $input-btn-padding-x !default;
12-
$btn-font-family: $input-btn-font-family !default;
13-
$btn-font-size: $input-btn-font-size !default;
14-
$btn-line-height: $input-btn-line-height !default;
10+
$btn-padding-y: .375rem !default;
11+
$btn-padding-x: .75rem !default;
12+
$btn-font-size: var(--font-size-base) !default;
13+
$btn-line-height: var(--line-height-base) !default;
1514
$btn-white-space: null !default; // Set to `nowrap` to prevent text wrapping
1615

1716
$btn-padding-y-xs: .125rem !default;
1817
$btn-padding-x-xs: .375rem !default;
1918
$btn-font-size-xs: var(--font-size-xs) !default;
2019
$btn-line-height-xs: 1.125rem !default;
2120

22-
$btn-padding-y-sm: $input-btn-padding-y-sm !default;
23-
$btn-padding-x-sm: $input-btn-padding-x-sm !default;
21+
$btn-padding-y-sm: .25rem !default;
22+
$btn-padding-x-sm: .5rem !default;
2423
$btn-font-size-sm: var(--font-size-sm) !default;
2524
$btn-line-height-sm: 1.125rem !default;
2625

27-
$btn-padding-y-lg: $input-btn-padding-y-lg !default;
28-
$btn-padding-x-lg: $input-btn-padding-x-lg !default;
29-
$btn-font-size-lg: 16px !default;
26+
$btn-padding-y-lg: .5rem !default;
27+
$btn-padding-x-lg: 1rem !default;
28+
$btn-font-size-lg: var(--font-size-md) !default;
3029
$btn-line-height-lg: 1.25rem !default;
3130

3231
// Intentionally left for folks who want it
@@ -35,9 +34,9 @@ $btn-line-height-lg: 1.25rem !default;
3534
// $btn-font-size-xl: var(--font-size-lg) !default;
3635
// $btn-line-height-xl: 1.5rem !default;
3736

38-
$btn-border-width: $input-btn-border-width !default;
37+
$btn-border-width: var(--border-width) !default;
3938

40-
$btn-font-weight: $font-weight-normal !default;
39+
$btn-font-weight: var(--font-weight-normal) !default;
4140
$btn-disabled-opacity: .65 !default;
4241

4342
$btn-link-color: var(--link-color) !default;

scss/buttons/_button.scss

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ $btn-variant-selectors: () !default;
138138
--btn-min-height: 2.25rem;
139139
--btn-padding-x: #{$btn-padding-x};
140140
--btn-padding-y: #{$btn-padding-y};
141-
--btn-font-family: #{$btn-font-family};
141+
// --btn-font-family: #{$btn-font-family};
142142
--btn-font-size: #{$btn-font-size};
143143
--btn-font-weight: #{$btn-font-weight};
144144
--btn-line-height: #{$btn-line-height};
@@ -156,7 +156,7 @@ $btn-variant-selectors: () !default;
156156
justify-content: center;
157157
min-height: var(--btn-min-height);
158158
padding: var(--btn-padding-y) var(--btn-padding-x);
159-
font-family: var(--btn-font-family);
159+
// font-family: var(--btn-font-family);
160160
font-size: var(--btn-font-size);
161161
font-weight: var(--btn-font-weight);
162162
line-height: var(--btn-line-height);
@@ -300,24 +300,27 @@ $btn-variant-selectors: () !default;
300300
--btn-bg: transparent;
301301
--btn-border-color: transparent;
302302
--btn-hover-color: #{$btn-link-hover-color};
303+
--btn-hover-bg: transparent;
303304
--btn-hover-border-color: transparent;
304305
--btn-active-color: #{$btn-link-hover-color};
306+
--btn-active-bg: transparent;
305307
--btn-active-border-color: transparent;
306308
--btn-disabled-color: #{$btn-link-disabled-color};
307309
--btn-disabled-border-color: transparent;
308310

311+
color: var(--theme-text, var(--btn-color));
309312
text-decoration: var(--link-decoration);
310313

311314
@if $enable-gradients {
312315
background-image: none;
313316
}
314317

315318
&:focus-visible {
316-
color: var(--btn-color);
319+
color: var(--theme-text, var(--btn-color));
317320
}
318321

319322
&:hover {
320-
color: var(--btn-hover-color);
323+
color: var(--theme-text-emphasis, var(--btn-hover-color));
321324
}
322325

323326
// No need for an active state here

scss/content/_reboot.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,14 @@
249249
// Links
250250

251251
a {
252-
color: var(--link-color);
252+
color: var(--theme-text, var(--link-color));
253253
text-decoration: var(--link-decoration);
254254
text-underline-offset: $link-underline-offset;
255255

256256
&:hover {
257257
// --link-color: var(--link-hover-color);
258258
// --link-decoration: var(--link-hover-decoration, var(--link-decoration));
259-
color: var(--link-hover-color);
259+
color: var(--theme-text-emphasis, var(--link-hover-color));
260260
text-decoration: var(--link-hover-decoration, var(--link-decoration));
261261
}
262262
}

scss/helpers/_colored-links.scss

Lines changed: 0 additions & 38 deletions
This file was deleted.

scss/helpers/index.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@forward "color-bg";
2-
@forward "colored-links";
32
@forward "focus-ring";
43
@forward "icon-link";
54
@forward "position";

site/data/sidebar.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
icon_color: orange
111111
pages:
112112
- title: Color & background
113-
- title: Colored links
114113
- title: Focus ring
115114
- title: Icon link
116115
- title: Position

site/src/components/shortcodes/ButtonPlayground.astro

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getData } from '@libs/data'
33
import Example from '@components/shortcodes/Example.astro'
44
55
const themeColors = getData('theme-colors')
6-
const styles = ['solid', 'styled', 'outline', 'subtle', 'text']
6+
const styles = ['styled', 'solid', 'outline', 'subtle', 'text']
77
const sizes = [
88
{ value: 'xs', label: 'Extra small' },
99
{ value: 'sm', label: 'Small' },
@@ -25,20 +25,23 @@ const rounded = ['default', 'pill', 'square']
2525
</symbol>
2626
</svg>
2727

28-
<div class="bg-1 p-3 rounded-3 mb-3">
28+
<div class="bg-1 p-3 rounded-3">
2929
<div class="d-flex flex-wrap gap-3">
30-
<div class="vstack gap-1 flex-grow-0">
30+
<div class="vstack gap-1">
3131
<label class="form-label fw-semibold mb-0">Color</label>
3232
<div class="dropdown">
3333
<button
3434
type="button"
35-
class="btn btn-outline theme-secondary dropdown-toggle w-100 d-inline-flex align-items-center justify-content-between"
35+
class="btn btn-outline theme-secondary dropdown-toggle w-100 justify-content-between"
3636
id="btn-color-dropdown"
3737
data-bs-toggle="dropdown"
3838
aria-expanded="false"
3939
data-color="primary"
4040
>
4141
Primary
42+
<svg class="bi ms-1" width="16" height="16" aria-hidden="true">
43+
<use href="#chevron-expand" />
44+
</svg>
4245
</button>
4346
<ul class="dropdown-menu" aria-labelledby="btn-color-dropdown">
4447
{themeColors.map((themeColor) => (
@@ -57,7 +60,7 @@ const rounded = ['default', 'pill', 'square']
5760
</div>
5861
</div>
5962

60-
<div class="vstack gap-1 flex-grow-0">
63+
<div class="vstack gap-1">
6164
<label class="form-label fw-semibold mb-0">Style</label>
6265
<div class="btn-group text-capitalize" role="group" aria-label="Button style">
6366
{styles.map((style) => (
@@ -66,7 +69,7 @@ const rounded = ['default', 'pill', 'square']
6669
type="radio"
6770
name="btn-style"
6871
value={style}
69-
checked={style === 'solid'}
72+
checked={style === 'styled'}
7073
data-style={style}
7174
/>
7275
{style || 'default'}
@@ -75,18 +78,21 @@ const rounded = ['default', 'pill', 'square']
7578
</div>
7679
</div>
7780

78-
<div class="vstack gap-1 flex-grow-0">
81+
<div class="vstack gap-1">
7982
<label class="form-label fw-semibold mb-0">Size</label>
8083
<div class="dropdown">
8184
<button
8285
type="button"
83-
class="btn btn-outline theme-secondary dropdown-toggle w-100 d-inline-flex align-items-center justify-content-between"
86+
class="btn btn-outline theme-secondary dropdown-toggle w-100 justify-content-between"
8487
id="btn-size-dropdown"
8588
data-bs-toggle="dropdown"
8689
aria-expanded="false"
8790
data-size=""
8891
>
8992
Medium
93+
<svg class="bi ms-1" width="16" height="16" aria-hidden="true">
94+
<use href="#chevron-expand" />
95+
</svg>
9096
</button>
9197
<ul class="dropdown-menu" aria-labelledby="btn-size-dropdown">
9298
{sizes.map((size) => (

site/src/content/docs/components/buttons.mdx

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ Buttons have a standard `.btn` class that sets up basic styles such as padding a
1414

1515
The `.btn` class is intended to be a starting point for your own custom button styles, while our provided button variants used in conjunction with our button variants, or to serve as a basis for your own custom styles.
1616

17-
<Callout type="warning">
18-
When using `.btn` without a modifier, be sure to add some explicit `:focus-visible` styles.
19-
</Callout>
20-
2117
## Playground
2218

2319
Bootstrap includes several button variants, each serving its own semantic purpose, with a few extras thrown in for more control. Combined with our utilities, you have a very powerful set of defaults to choose from.
@@ -26,17 +22,25 @@ Bootstrap includes several button variants, each serving its own semantic purpos
2622

2723
## Variants
2824

29-
Compare all variants at once:
25+
Compare all button variants and styles at once:
3026

31-
<Example class="bd-example-buttons" code={[...getData('theme-colors').map((themeColor) => `<button type="button" class="btn-solid theme-${themeColor.name} justify-self-start">${themeColor.title}</button>
32-
<button type="button" class="btn-outline theme-${themeColor.name} justify-self-start">${themeColor.title}</button>
33-
<button type="button" class="btn-subtle theme-${themeColor.name} justify-self-start">${themeColor.title}</button>
34-
<button type="button" class="btn-text theme-${themeColor.name} justify-self-start">${themeColor.title}</button>
35-
`), `
36-
<button type="button" class="btn btn-link">Link</button>`]} />
27+
<Example class="bd-example-buttons justify-items-start" code={[...getData('theme-colors').map((themeColor) => `<button type="button" class="btn-solid theme-${themeColor.name}">${themeColor.title}</button>
28+
<button type="button" class="btn-outline theme-${themeColor.name}">${themeColor.title}</button>
29+
<button type="button" class="btn-subtle theme-${themeColor.name}">${themeColor.title}</button>
30+
<button type="button" class="btn-text theme-${themeColor.name}">${themeColor.title}</button>`)]} />
3731

3832
<Details name="warning-color-assistive-technologies" />
3933

34+
## Link buttons
35+
36+
Use the `.btn-link` class to create a button that looks like a link.
37+
38+
<Example code={`<button type="button" class="btn btn-link">Link</button>`} />
39+
40+
Link buttons can also be styled with the theme colors.
41+
42+
<Example code={[...getData('theme-colors').map((themeColor) => `<button type="button" class="btn btn-link theme-${themeColor.name}">${themeColor.title}</button>`)]} />
43+
4044
## Styled buttons
4145

4246
Add visual depth to solid buttons with gradients and shadows using the `.btn-styled` modifier class. This provides a more three-dimensional appearance that can be customized further with CSS variables.
@@ -58,10 +62,6 @@ The gradient and shadow can be customized via CSS variables:
5862
| `--bs-btn-active-shadow` | Pressed/active state shadow |
5963
</BsTable>
6064

61-
## Disable text wrapping
62-
63-
If you don’t want the button text to wrap, you can add the `.text-nowrap` class to the button. In Sass, you can set `$btn-white-space: nowrap` to disable text wrapping for each button.
64-
6565
## Button tags
6666

6767
The `.btn` classes are designed to be used with the `<button>` element. However, you can also use these classes on `<a>` or `<input>` elements (though some browsers may apply a slightly different rendering).
@@ -125,16 +125,14 @@ Combine with size classes for different icon button sizes:
125125

126126
## Disabled state
127127

128-
Make buttons look inactive by adding the `disabled` boolean attribute to any `<button>` element. Disabled buttons have `pointer-events: none` applied to, preventing hover and active states from triggering, and some additional styling to indicate the disabled state.
128+
Make buttons look inactive by adding the `disabled` boolean attribute to any `<button>` element. Disabled buttons have `pointer-events: none`, preventing hover and active states from triggering, and some additional styling to indicate the disabled state.
129129

130130
<Example code={`<button type="button" class="btn-solid theme-primary" disabled>Primary button</button>
131131
<button type="button" class="btn-solid theme-secondary" disabled>Button</button>
132132
<button type="button" class="btn-outline theme-primary" disabled>Primary button</button>
133133
<button type="button" class="btn-outline theme-secondary" disabled>Button</button>`} />
134134

135-
### Disabled links
136-
137-
Disabled buttons using the `<a>` element behave a bit different, and if you need to keep the `href` attribute, you may need additional HTML to fully disable the link functionality. Use the `.disabled` class instead of the attribute on `<a>` elements to make them visually appear disabled.
135+
Disabled buttons using the `<a>` element behave a bit different. Use the `.disabled` class instead of the attribute on `<a>` elements to make them visually appear disabled. If you need to keep the `href` attribute, you may need additional HTML to fully disable the link functionality.
138136

139137
<Example code={`<a class="btn-solid theme-primary disabled" role="button" aria-disabled="true">Primary link</a>
140138
<a class="btn-solid theme-secondary disabled" role="button" aria-disabled="true">Link</a>`} />

0 commit comments

Comments
 (0)