Skip to content

Commit ac0b87b

Browse files
authored
Don't style readonly inputs as disabled (#36499)
* Don't style readonly inputs as disabled Also remove the Chrome-specific focus styling from readonly plaintext * Update some docs comments
1 parent dfe7472 commit ac0b87b

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

scss/forms/_form-control.scss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@
5959
opacity: 1;
6060
}
6161

62-
// Disabled and read-only inputs
62+
// Disabled inputs
6363
//
6464
// HTML5 says that controls under a fieldset > legend:first-child won't be
6565
// disabled if the fieldset is disabled. Due to implementation difficulty, we
6666
// don't honor that edge case; we style them as disabled anyway.
67-
&:disabled,
68-
&[readonly] {
67+
&:disabled {
6968
color: $input-disabled-color;
7069
background-color: $input-disabled-bg;
7170
border-color: $input-disabled-border-color;
@@ -110,6 +109,10 @@
110109
border: solid transparent;
111110
border-width: $input-border-width 0;
112111

112+
&:focus {
113+
outline: 0;
114+
}
115+
113116
&.form-control-sm,
114117
&.form-control-lg {
115118
padding-right: 0;

site/content/docs/5.2/forms/form-control.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Set heights using classes like `.form-control-lg` and `.form-control-sm`.
3131

3232
## Disabled
3333

34-
Add the `disabled` boolean attribute on an input to give it a grayed out appearance and remove pointer events.
34+
Add the `disabled` boolean attribute on an input to give it a grayed out appearance, remove pointer events, and prevent focusing.
3535

3636
{{< example >}}
3737
<input class="form-control" type="text" placeholder="Disabled input" aria-label="Disabled input example" disabled>
@@ -40,15 +40,15 @@ Add the `disabled` boolean attribute on an input to give it a grayed out appeara
4040

4141
## Readonly
4242

43-
Add the `readonly` boolean attribute on an input to prevent modification of the input's value.
43+
Add the `readonly` boolean attribute on an input to prevent modification of the input's value. `readonly` inputs can still be focused and selected, while `disabled` inputs cannot.
4444

4545
{{< example >}}
4646
<input class="form-control" type="text" value="Readonly input here..." aria-label="readonly input example" readonly>
4747
{{< /example >}}
4848

4949
## Readonly plain text
5050

51-
If you want to have `<input readonly>` elements in your form styled as plain text, use the `.form-control-plaintext` class to remove the default form field styling and preserve the correct margin and padding.
51+
If you want to have `<input readonly>` elements in your form styled as plain text, replace `.form-control` with `.form-control-plaintext` to remove the default form field styling and preserve the correct `margin` and `padding`.
5252

5353
{{< example >}}
5454
<div class="mb-3 row">

0 commit comments

Comments
 (0)