Skip to content

Commit a7fbc70

Browse files
abhiomkarcopybara-github
authored andcommitted
feat(radio): Added reducedTouchTarget support to mwc-radio
PiperOrigin-RevId: 331779945
1 parent b102a3c commit a7fbc70

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

packages/checkbox/mwc-checkbox-base.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ export class CheckboxBase extends FormElement {
3737

3838
@property({type: String}) value = '';
3939

40+
/**
41+
* Touch target extends beyond visual boundary of a component by default.
42+
* Set to `true` to remove touch target added to the component.
43+
* @see https://material.io/design/usability/accessibility.html
44+
*/
4045
@property({type: Boolean}) reducedTouchTarget = false;
4146

4247
@internalProperty() protected animationClass = '';

packages/radio/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,14 @@ to associate an interactive label with the radio.
108108

109109
### Properties/Attributes
110110

111-
| Name | Type | Default | Description
112-
| --------------- | --------- |-------- | -----------
113-
| `checked` | `boolean` | `false` | Whether this radio button is the currently-selected one in its group. Maps to the native [`checked`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#checked) attribute.
114-
| `disabled` | `boolean` | `false` | If `true`, this radio button cannot be selected or de-selected. Maps to the native [`disabled`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#disabled) attribute.
115-
| `name` | `string` | `''` | Name of the input for form submission, and identifier for the selection group. Only one radio button can be checked for a given selection group. Maps to the native [`name`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#name) attribute.
116-
| `value` | `string` | `''` | Value of the input for form submission. Maps to the native [`value`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#value) attribute.
117-
| `global` | `boolean` | `false` | If `true`, this radio button will use a global, document-level scope for its selection group rather than its local shadow root.
111+
Name | Type | Default | Description
112+
-------------------- | --------- | ------- | -----------
113+
`checked` | `boolean` | `false` | Whether this radio button is the currently-selected one in its group. Maps to the native [`checked`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#checked) attribute.
114+
`disabled` | `boolean` | `false` | If `true`, this radio button cannot be selected or de-selected. Maps to the native [`disabled`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#disabled) attribute.
115+
`name` | `string` | `''` | Name of the input for form submission, and identifier for the selection group. Only one radio button can be checked for a given selection group. Maps to the native [`name`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#name) attribute.
116+
`value` | `string` | `''` | Value of the input for form submission. Maps to the native [`value`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#value) attribute.
117+
`global` | `boolean` | `false` | If `true`, this radio button will use a global, document-level scope for its selection group rather than its local shadow root.
118+
`reducedTouchTarget` | `boolean` | `false` | When `true`, the radio removes touch target that extends beyond visual boundary of the component. Set to `false` by default to meet Material [accessibility guidelines](https://material.io/design/usability/accessibility.html).
118119

119120
### Methods
120121
*None*

packages/radio/mwc-radio-base.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {RippleHandlers} from '@material/mwc-ripple/ripple-handlers';
2222
import {MDCRadioAdapter} from '@material/radio/adapter';
2323
import MDCRadioFoundation from '@material/radio/foundation';
2424
import {eventOptions, html, internalProperty, property, query, queryAsync} from 'lit-element';
25+
import {classMap} from 'lit-html/directives/class-map';
2526

2627

2728
/**
@@ -100,6 +101,13 @@ export class RadioBase extends FormElement {
100101

101102
@property({type: String}) name = '';
102103

104+
/**
105+
* Touch target extends beyond visual boundary of a component by default.
106+
* Set to `true` to remove touch target added to the component.
107+
* @see https://material.io/design/usability/accessibility.html
108+
*/
109+
@property({type: Boolean}) reducedTouchTarget = false;
110+
103111
protected mdcFoundationClass = MDCRadioFoundation;
104112

105113
protected mdcFoundation!: MDCRadioFoundation;
@@ -198,16 +206,25 @@ export class RadioBase extends FormElement {
198206

199207
/**
200208
* @soyCompatible
209+
* @soyAttributes radioAttributes: input
210+
* @soyClasses radioClasses: .mdc-radio
201211
*/
202212
protected render() {
213+
/** @classMap */
214+
const classes = {
215+
'mdc-radio--touch': !this.reducedTouchTarget,
216+
'mdc-radio--disabled': this.disabled,
217+
};
218+
203219
return html`
204-
<div class="mdc-radio">
220+
<div class="mdc-radio ${classMap(classes)}">
205221
<input
206222
class="mdc-radio__native-control"
207223
type="radio"
208224
name="${this.name}"
209225
.checked="${this.checked}"
210226
.value="${this.value}"
227+
?disabled="${this.disabled}"
211228
@change="${this.changeHandler}"
212229
@focus="${this.handleFocus}"
213230
@click="${this.handleClick}"

0 commit comments

Comments
 (0)