| 1 |
--- |
| 2 |
id: Radio |
| 3 |
section: components |
| 4 |
subsection: forms |
| 5 |
cssPrefix: pf-v6-c-radio |
| 6 |
---## Examples |
| 7 |
|
| 8 |
### Basic |
| 9 |
|
| 10 |
```html |
| 11 |
<div class="pf-v6-c-radio" id="radio-basic-example"> |
| 12 |
<input |
| 13 |
class="pf-v6-c-radio__input" |
| 14 |
type="radio" |
| 15 |
id="radio-basic-example-input" |
| 16 |
name="radio-basic-example-input" |
| 17 |
/> |
| 18 |
<label |
| 19 |
class="pf-v6-c-radio__label" |
| 20 |
for="radio-basic-example-input" |
| 21 |
>Basic radio</label> |
| 22 |
</div> |
| 23 |
|
| 24 |
``` |
| 25 |
|
| 26 |
### Checked |
| 27 |
|
| 28 |
```html |
| 29 |
<div class="pf-v6-c-radio" id="radio-checked-example"> |
| 30 |
<input |
| 31 |
class="pf-v6-c-radio__input" |
| 32 |
type="radio" |
| 33 |
id="radio-checked-example-input" |
| 34 |
name="radio-checked-example-input" |
| 35 |
checked |
| 36 |
/> |
| 37 |
<label |
| 38 |
class="pf-v6-c-radio__label" |
| 39 |
for="radio-checked-example-input" |
| 40 |
>Radio checked</label> |
| 41 |
</div> |
| 42 |
|
| 43 |
``` |
| 44 |
|
| 45 |
### Label wrapping input |
| 46 |
|
| 47 |
```html |
| 48 |
<label |
| 49 |
class="pf-v6-c-radio" |
| 50 |
id="radio-label-wrapping-input-example" |
| 51 |
for="radio-label-wrapping-input-example-input" |
| 52 |
> |
| 53 |
<input |
| 54 |
class="pf-v6-c-radio__input" |
| 55 |
type="radio" |
| 56 |
id="radio-label-wrapping-input-example-input" |
| 57 |
name="radio-label-wrapping-input-example-input" |
| 58 |
/> |
| 59 |
<span class="pf-v6-c-radio__label">Radio label wraps input</span> |
| 60 |
</label> |
| 61 |
|
| 62 |
``` |
| 63 |
|
| 64 |
### Reversed |
| 65 |
|
| 66 |
```html |
| 67 |
<div class="pf-v6-c-radio" id="radio-reversed-example"> |
| 68 |
<label |
| 69 |
class="pf-v6-c-radio__label" |
| 70 |
for="radio-reversed-example-input" |
| 71 |
>Radio reversed</label> |
| 72 |
<input |
| 73 |
class="pf-v6-c-radio__input" |
| 74 |
type="radio" |
| 75 |
id="radio-reversed-example-input" |
| 76 |
name="radio-reversed-example-input" |
| 77 |
/> |
| 78 |
</div> |
| 79 |
|
| 80 |
``` |
| 81 |
|
| 82 |
### Disabled |
| 83 |
|
| 84 |
```html |
| 85 |
<div class="pf-v6-c-radio" id="radio-disabled-example"> |
| 86 |
<input |
| 87 |
class="pf-v6-c-radio__input" |
| 88 |
type="radio" |
| 89 |
id="radio-disabled-example-input" |
| 90 |
name="radio-disabled-example-input" |
| 91 |
disabled |
| 92 |
/> |
| 93 |
<label |
| 94 |
class="pf-v6-c-radio__label pf-m-disabled" |
| 95 |
for="radio-disabled-example-input" |
| 96 |
>Radio disabled</label> |
| 97 |
</div> |
| 98 |
<div class="pf-v6-c-radio" id="radio-disabled-checked-example"> |
| 99 |
<input |
| 100 |
class="pf-v6-c-radio__input" |
| 101 |
type="radio" |
| 102 |
id="radio-disabled-checked-example-input" |
| 103 |
name="radio-disabled-checked-example-input" |
| 104 |
checked |
| 105 |
disabled |
| 106 |
/> |
| 107 |
<label |
| 108 |
class="pf-v6-c-radio__label pf-m-disabled" |
| 109 |
for="radio-disabled-checked-example-input" |
| 110 |
>Radio disabled checked</label> |
| 111 |
</div> |
| 112 |
|
| 113 |
``` |
| 114 |
|
| 115 |
### With description |
| 116 |
|
| 117 |
```html |
| 118 |
<div class="pf-v6-c-radio" id="radio-with-description-exmaple"> |
| 119 |
<input |
| 120 |
class="pf-v6-c-radio__input" |
| 121 |
type="radio" |
| 122 |
aria-describedby="radio-with-description-exmaple-description" |
| 123 |
id="radio-with-description-exmaple-input" |
| 124 |
name="radio-with-description-exmaple-input" |
| 125 |
/> |
| 126 |
<label |
| 127 |
class="pf-v6-c-radio__label" |
| 128 |
for="radio-with-description-exmaple-input" |
| 129 |
>Radio with description</label> |
| 130 |
<span |
| 131 |
class="pf-v6-c-radio__description" |
| 132 |
id="radio-with-description-exmaple-description" |
| 133 |
>Single-tenant cloud service hosted and managed by Red Hat that offers high-availability enterprise-grade clusters in a virtual private cloud on AWS od GCP.</span> |
| 134 |
</div> |
| 135 |
|
| 136 |
``` |
| 137 |
|
| 138 |
### With body |
| 139 |
|
| 140 |
```html |
| 141 |
<div class="pf-v6-c-radio" id="radio-with-body-example"> |
| 142 |
<input |
| 143 |
class="pf-v6-c-radio__input" |
| 144 |
type="radio" |
| 145 |
id="radio-with-body-example-input" |
| 146 |
name="radio-with-body-example-input" |
| 147 |
/> |
| 148 |
<label |
| 149 |
class="pf-v6-c-radio__label" |
| 150 |
for="radio-with-body-example-input" |
| 151 |
>Radio with body</label> |
| 152 |
<span class="pf-v6-c-radio__body">This is where custom content goes.</span> |
| 153 |
</div> |
| 154 |
|
| 155 |
``` |
| 156 |
|
| 157 |
### With description and body |
| 158 |
|
| 159 |
```html |
| 160 |
<div class="pf-v6-c-radio" id="radio-with-description-body-example"> |
| 161 |
<input |
| 162 |
class="pf-v6-c-radio__input" |
| 163 |
type="radio" |
| 164 |
aria-describedby="radio-with-description-body-example-description" |
| 165 |
id="radio-with-description-body-example-input" |
| 166 |
name="radio-with-description-body-example-input" |
| 167 |
/> |
| 168 |
<label |
| 169 |
class="pf-v6-c-radio__label" |
| 170 |
for="radio-with-description-body-example-input" |
| 171 |
>Radio with description and body</label> |
| 172 |
<span |
| 173 |
class="pf-v6-c-radio__description" |
| 174 |
id="radio-with-description-body-example-description" |
| 175 |
>Single-tenant cloud service hosted and managed by Red Hat that offers high-availability enterprise-grade clusters in a virtual private cloud on AWS od GCP.</span> |
| 176 |
<span class="pf-v6-c-radio__body">This is where custom content goes.</span> |
| 177 |
</div> |
| 178 |
|
| 179 |
``` |
| 180 |
|
| 181 |
### Standalone input |
| 182 |
|
| 183 |
```html |
| 184 |
<label class="pf-v6-c-radio pf-m-standalone" id="radio-standalon-input-example"> |
| 185 |
<input |
| 186 |
class="pf-v6-c-radio__input" |
| 187 |
type="radio" |
| 188 |
id="radio-standalon-input-example-input" |
| 189 |
name="radio-standalon-input-example-input" |
| 190 |
aria-label="Standalone radio" |
| 191 |
/> |
| 192 |
</label> |
| 193 |
|
| 194 |
``` |
| 195 |
|
| 196 |
## Documentation |
| 197 |
|
| 198 |
### Overview |
| 199 |
|
| 200 |
The Radio component is provided for use cases outside of forms. If it is used without label text ensure some sort of label for assistive technologies. (for example: `aria-label`) |
| 201 |
|
| 202 |
If you extend this component or modify the styles of this component, then make sure any hover styles defined are applied to the clickable elements, like `<input>` or `<label>` since hover styles are used to convey the clickable target area of an element. To maximize the target area, use the example html where the `<label>` is the wrapping element. |
| 203 |
|
| 204 |
### Accessibility |
| 205 |
|
| 206 |
| Attribute | Applied to | Outcome | |
| 207 |
| -- | -- | -- | |
| 208 |
| `disabled` | `<input type="radio">` | Indicates that the element is unavailable and removes it from keyboard focus. **Required when input is disabled** | |
| 209 |
| `aria-describedby` | `.pf-v6-c-radio__input` | When using `.pf-v6-c-radio__description` make use of this on the input. | |
| 210 |
|
| 211 |
### Usage |
| 212 |
|
| 213 |
| Class | Applied to | Outcome | |
| 214 |
| -- | -- | -- | |
| 215 |
| `.pf-v6-c-radio` | `<div>`, `<label>` | Initiates the radio component. **Required** | |
| 216 |
| `.pf-v6-c-radio__input` | `<input type="radio">` | Initiates a radio input. **Required** | |
| 217 |
| `.pf-v6-c-radio__label` | `<label>`, `<span>` | Initiates a label. **Required** | |
| 218 |
| `.pf-v6-c-radio__description` | `<span>` | Initiates a radio description. | |
| 219 |
| `.pf-v6-c-radio__body` | `<span>` | Initiates a radio body. | |
| 220 |
| `.pf-m-standalone` | `.pf-v6-c-radio` | Modifies the radio component for use with a standalone `<input type="radio">`. **Required when there is no label** | |
| 221 |
| `.pf-m-disabled` | `.pf-v6-c-radio__label` | Modifies the radio component for the disabled state. **Required when input is disabled** | |