Skip to content

Commit

Permalink
Document Switch
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 494890466
  • Loading branch information
material-web-copybara authored and copybara-github committed Dec 13, 2022
1 parent a5850dc commit c8341bb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
38 changes: 31 additions & 7 deletions switch/lib/switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

// tslint:disable:no-new-decorators

import '../../focus/focus-ring.js';
import '../../ripple/ripple.js';

Expand All @@ -23,20 +25,33 @@ export class Switch extends ActionElement {
static override shadowRootOptions:
ShadowRootInit = {mode: 'open', delegatesFocus: true};

/**
* Disables the switch and makes it non-interactive.
*/
@property({type: Boolean, reflect: true}) disabled = false;
@property({type: Boolean}) processing = false;

/**
* Puts the switch in the selected state and sets the form submission value to
* the `value` property.
*/
@property({type: Boolean}) selected = false;

/**
* Shows both the selected and deselected icons.
*/
@property({type: Boolean}) icons = false;

/**
* Shows only the selected icon, and not the deselected icon. If `true`,
* overrides the behavior of the `icons` property.
*/
@property({type: Boolean}) showOnlySelectedIcon = false;

// Aria
@ariaProperty // tslint:disable-line:no-new-decorators
// TODO(b/210730484): replace with @soyParam annotation
@ariaProperty
@property({type: String, attribute: 'data-aria-label', noAccessor: true})
override ariaLabel!: string;

// TODO: Add support in @ariaProperty for idref aria attributes
@ariaProperty // tslint:disable-line:no-new-decorators
@ariaProperty
@property({type: String, attribute: 'data-aria-labelledby', noAccessor: true})
ariaLabelledBy = '';

Expand All @@ -49,8 +64,18 @@ export class Switch extends ActionElement {
get form() {
return this.closest('form');
}

/**
* The HTML name to use in form submission.
*/
@property({type: String, reflect: true}) name = '';

/**
* The value associated with this switch on form submission. `null` is
* submitted when `selected` is `false`.
*/
@property({type: String}) value = 'on';

[getFormValue]() {
return this.selected ? this.value : null;
}
Expand Down Expand Up @@ -110,7 +135,6 @@ export class Switch extends ActionElement {
/** @soyTemplate */
protected getRenderClasses(): ClassInfo {
return {
'md3-switch--processing': this.processing,
'md3-switch--selected': this.selected,
'md3-switch--unselected': !this.selected,
};
Expand Down
6 changes: 0 additions & 6 deletions switch/lib/switch_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ describe('md-switch', () => {
});
});

describe('processing', () => {
it('is false by default', () => {
expect(toggle.processing).toBeFalse();
});
});

describe('disabled', () => {
let disabled: TestSwitch;

Expand Down
6 changes: 6 additions & 0 deletions switch/switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ declare global {
}

/**
* @summary Switches toggle the state of a single item on or off.
*
* @description
* There's one type of switch in Material. Use this selection control when the
* user needs to toggle a single item on or off.
*
* @soyCompatible
* @final
* @suppress {visibility}
Expand Down

0 comments on commit c8341bb

Please sign in to comment.