Skip to content

Commit

Permalink
docs: add radio docs
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 552945498
  • Loading branch information
asyncLiz authored and copybara-github committed Aug 1, 2023
1 parent ce248dc commit 6aa42f3
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/components/checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ more descriptive.
</label>
```

> Note: checkboxes are not automatically labelled by `<label>` elements and
> always need an `aria-label`. See b/294081528.
## Theming

Checkbox supports [Material theming](../theming.md) and can be customized in
Expand Down
Binary file added docs/components/images/radio/hero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
147 changes: 147 additions & 0 deletions docs/components/radio.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<!-- catalog-only-start --><!-- ---
name: Radio
dirname: radio
ssrOnly: true
-----><!-- catalog-only-end -->

<catalog-component-header image-align="start">
<catalog-component-header-title slot="title">

# Radio button

<!--*
# Document freshness: For more information, see go/fresh-source.
freshness: { owner: 'lizmitchell' reviewed: '2023-08-01' }
tag: 'docType:reference'
*-->

<!-- github-only-start -->

<!-- go/md-radio -->

<!-- [TOC] -->

<!-- github-only-end -->

[Radio buttons](https://m3.material.io/components/radio-button)<!-- {.external} --> let
people select one option from a set of options.

</catalog-component-header-title>

<img
class="hero"
src="images/radio/hero.png"
alt="A list of items with radio buttons and one selected."
title="Radio buttons">

</catalog-component-header>

* [Design article](https://m3.material.io/components/radio-button) <!-- {.external} -->
* API Documentation (*coming soon*)
* [Source code](https://github.com/material-components/material-web/tree/main/radio)
<!-- {.external} -->

<!-- catalog-only-start -->

<!--
## Interactive Demo
{% playgroundexample dirname=dirname %}
-->

<!-- catalog-only-end -->

## Usage

Radios behave like
[`<input type="radio">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio)<!-- {.external} -->
elements and form a group with the same `name` attribute. Only one radio can be
selected in a group.

Radios can be pre-selected by adding a `selected` attribute.

Add a `value` to identify which radio is selected in a form.

<!-- TODO: add image example -->

```html
<form>
<md-radio name="animals" value="cats"></md-radio>
<md-radio name="animals" value="dogs"></md-radio>
<md-radio name="animals" value="birds" selected></md-radio>
</form>
```

### Label

Associate a label with a radio using the `<label>` element.

<!-- TODO: add image example -->

```html
<label>
<md-radio name="animals" value="cats"></md-radio>
Cats
</label>

<md-radio id="dogs-radio" name="animals" value="dogs"></md-radio>
<label for="dogs-radio">Dogs</label>
```

## Accessibility

Add an
[`aria-label`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label)<!-- {.external} -->
attribute to radios without labels or radios whose labels need to be more
descriptive.

<!-- TODO: add image example -->

```html
<label>
<md-radio name="group" value="1" aria-label="First"></md-radio>
1st
</label>
<label>
<md-radio name="group" value="2" aria-label="Second"></md-radio>
2nd
</label>
```

> Note: radios are not automatically labelled by `<label>` elements and always
> need an `aria-label`. See b/294081528.
## Theming

Radios support [Material theming](../theming.md) and can be customized in terms
of color.

### Tokens

Token | Default value
-------------------------------- | -----------------------------------
`--md-radio-icon-color` | `--md-sys-color-on-surface-variant`
`--md-radio-selected-icon-color` | `--md-sys-color-primary`
`--md-radio-icon-size` | `20px`

* [All tokens](https://github.com/material-components/material-web/blob/main/tokens/_md-comp-radio.scss)
<!-- {.external} -->

### Example

<!-- TODO: add image example -->

```html
<style>
:root {
--md-sys-color-primary: #006A6A;
--md-radio-icon-size: 16px;
}
</style>

<md-radio name="group"></md-radio>
<md-radio name="group" selected></md-radio>
<md-radio name="group"></md-radio>
```

0 comments on commit 6aa42f3

Please sign in to comment.