@material/mwc-radio
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -18,3 +18,3 @@ /** | ||
import { css } from '@material/mwc-base/base-element'; | ||
export const style = css `.mdc-radio{display:inline-block;position:relative;flex:0 0 auto;box-sizing:border-box;width:40px;height:40px;padding:10px;cursor:pointer;will-change:opacity,transform,border-color,color}.mdc-radio .mdc-radio__native-control:enabled:not(:checked)+.mdc-radio__background .mdc-radio__outer-circle{border-color:rgba(0,0,0,.54)}.mdc-radio .mdc-radio__native-control:enabled:checked+.mdc-radio__background .mdc-radio__outer-circle{border-color:#018786;border-color:var(--mdc-theme-secondary, #018786)}.mdc-radio .mdc-radio__native-control:enabled+.mdc-radio__background .mdc-radio__inner-circle{border-color:#018786;border-color:var(--mdc-theme-secondary, #018786)}.mdc-radio .mdc-radio__background::before{background-color:#018786}@supports not (-ms-ime-align: auto){.mdc-radio .mdc-radio__background::before{background-color:var(--mdc-theme-secondary, #018786)}}.mdc-radio__background{display:inline-block;position:absolute;left:10px;box-sizing:border-box;width:50%;height:50%}.mdc-radio__background::before{position:absolute;top:0;left:0;width:100%;height:100%;transform:scale(0, 0);border-radius:50%;opacity:0;pointer-events:none;content:"";transition:opacity 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1),transform 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1)}.mdc-radio__outer-circle{position:absolute;top:0;left:0;box-sizing:border-box;width:100%;height:100%;border-width:2px;border-style:solid;border-radius:50%;transition:border-color 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1)}.mdc-radio__inner-circle{position:absolute;top:0;left:0;box-sizing:border-box;width:100%;height:100%;transform:scale(0, 0);border-width:10px;border-style:solid;border-radius:50%;transition:transform 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1),border-color 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1)}.mdc-radio__native-control{position:absolute;top:0;left:0;width:100%;height:100%;margin:0;padding:0;opacity:0;cursor:inherit;z-index:1}.mdc-radio__native-control:checked+.mdc-radio__background,.mdc-radio__native-control:disabled+.mdc-radio__background{transition:opacity 120ms 0ms cubic-bezier(0, 0, 0.2, 1),transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio__native-control:checked+.mdc-radio__background .mdc-radio__outer-circle,.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__outer-circle{transition:border-color 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio__native-control:checked+.mdc-radio__background .mdc-radio__inner-circle,.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__inner-circle{transition:transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1),border-color 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio--disabled{cursor:default;pointer-events:none}.mdc-radio__native-control:checked+.mdc-radio__background .mdc-radio__inner-circle{transform:scale(0.5);transition:transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1),border-color 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio__native-control:disabled+.mdc-radio__background,[aria-disabled=true] .mdc-radio__native-control+.mdc-radio__background{cursor:default}.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__outer-circle,[aria-disabled=true] .mdc-radio__native-control+.mdc-radio__background .mdc-radio__outer-circle{border-color:rgba(0,0,0,.26)}.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__inner-circle,[aria-disabled=true] .mdc-radio__native-control+.mdc-radio__background .mdc-radio__inner-circle{border-color:rgba(0,0,0,.26)}.mdc-radio__native-control:focus+.mdc-radio__background::before{transform:scale(2, 2);opacity:.12;transition:opacity 120ms 0ms cubic-bezier(0, 0, 0.2, 1),transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}@keyframes mdc-ripple-fg-radius-in{from{animation-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transform:translate(var(--mdc-ripple-fg-translate-start, 0)) scale(1)}to{transform:translate(var(--mdc-ripple-fg-translate-end, 0)) scale(var(--mdc-ripple-fg-scale, 1))}}@keyframes mdc-ripple-fg-opacity-in{from{animation-timing-function:linear;opacity:0}to{opacity:var(--mdc-ripple-fg-opacity, 0)}}@keyframes mdc-ripple-fg-opacity-out{from{animation-timing-function:linear;opacity:var(--mdc-ripple-fg-opacity, 0)}to{opacity:0}}.mdc-ripple-surface--test-edge-var-bug{--mdc-ripple-surface-test-edge-var: 1px solid #000;visibility:hidden}.mdc-ripple-surface--test-edge-var-bug::before{border:var(--mdc-ripple-surface-test-edge-var)}.mdc-radio{--mdc-ripple-fg-size: 0;--mdc-ripple-left: 0;--mdc-ripple-top: 0;--mdc-ripple-fg-scale: 1;--mdc-ripple-fg-translate-end: 0;--mdc-ripple-fg-translate-start: 0;-webkit-tap-highlight-color:rgba(0,0,0,0);will-change:transform,opacity}.mdc-radio::before,.mdc-radio::after{position:absolute;border-radius:50%;opacity:0;pointer-events:none;content:""}.mdc-radio::before{transition:opacity 15ms linear,background-color 15ms linear;z-index:1}.mdc-radio.mdc-ripple-upgraded::before{transform:scale(var(--mdc-ripple-fg-scale, 1))}.mdc-radio.mdc-ripple-upgraded::after{top:0;left:0;transform:scale(0);transform-origin:center center}.mdc-radio.mdc-ripple-upgraded--unbounded::after{top:var(--mdc-ripple-top, 0);left:var(--mdc-ripple-left, 0)}.mdc-radio.mdc-ripple-upgraded--foreground-activation::after{animation:mdc-ripple-fg-radius-in 225ms forwards,mdc-ripple-fg-opacity-in 75ms forwards}.mdc-radio.mdc-ripple-upgraded--foreground-deactivation::after{animation:mdc-ripple-fg-opacity-out 150ms;transform:translate(var(--mdc-ripple-fg-translate-end, 0)) scale(var(--mdc-ripple-fg-scale, 1))}.mdc-radio::before,.mdc-radio::after{top:calc(50% - 50%);left:calc(50% - 50%);width:100%;height:100%}.mdc-radio.mdc-ripple-upgraded::before,.mdc-radio.mdc-ripple-upgraded::after{top:var(--mdc-ripple-top, calc(50% - 50%));left:var(--mdc-ripple-left, calc(50% - 50%));width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}.mdc-radio.mdc-ripple-upgraded::after{width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}.mdc-radio::before,.mdc-radio::after{background-color:#018786}@supports not (-ms-ime-align: auto){.mdc-radio::before,.mdc-radio::after{background-color:var(--mdc-theme-secondary, #018786)}}.mdc-radio:hover::before{opacity:.04}.mdc-radio:not(.mdc-ripple-upgraded):focus::before,.mdc-radio.mdc-ripple-upgraded--background-focused::before{transition-duration:75ms;opacity:.12}.mdc-radio:not(.mdc-ripple-upgraded)::after{transition:opacity 150ms linear}.mdc-radio:not(.mdc-ripple-upgraded):active::after{transition-duration:75ms;opacity:.12}.mdc-radio.mdc-ripple-upgraded{--mdc-ripple-fg-opacity: 0.12}.mdc-radio.mdc-ripple-upgraded--background-focused .mdc-radio__background::before{content:none}:host{display:inline-block;outline:none}`; | ||
export const style = css `.mdc-radio{display:inline-block;position:relative;flex:0 0 auto;box-sizing:border-box;width:40px;height:40px;padding:10px;cursor:pointer;will-change:opacity,transform,border-color,color}.mdc-radio .mdc-radio__native-control:enabled:not(:checked)+.mdc-radio__background .mdc-radio__outer-circle{border-color:rgba(0,0,0,.54)}.mdc-radio .mdc-radio__native-control:enabled:checked+.mdc-radio__background .mdc-radio__outer-circle{border-color:#018786;border-color:var(--mdc-theme-secondary, #018786)}.mdc-radio .mdc-radio__native-control:enabled+.mdc-radio__background .mdc-radio__inner-circle{border-color:#018786;border-color:var(--mdc-theme-secondary, #018786)}.mdc-radio .mdc-radio__background::before{background-color:#018786}@supports not (-ms-ime-align: auto){.mdc-radio .mdc-radio__background::before{background-color:var(--mdc-theme-secondary, #018786)}}.mdc-radio__background{display:inline-block;position:absolute;left:10px;box-sizing:border-box;width:50%;height:50%}.mdc-radio__background::before{position:absolute;top:0;left:0;width:100%;height:100%;transform:scale(0, 0);border-radius:50%;opacity:0;pointer-events:none;content:"";transition:opacity 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1),transform 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1)}.mdc-radio__outer-circle{position:absolute;top:0;left:0;box-sizing:border-box;width:100%;height:100%;border-width:2px;border-style:solid;border-radius:50%;transition:border-color 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1)}.mdc-radio__inner-circle{position:absolute;top:0;left:0;box-sizing:border-box;width:100%;height:100%;transform:scale(0, 0);border-width:10px;border-style:solid;border-radius:50%;transition:transform 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1),border-color 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1)}.mdc-radio__native-control{position:absolute;top:0;left:0;width:100%;height:100%;margin:0;padding:0;opacity:0;cursor:inherit;z-index:1}.mdc-radio__native-control:checked+.mdc-radio__background,.mdc-radio__native-control:disabled+.mdc-radio__background{transition:opacity 120ms 0ms cubic-bezier(0, 0, 0.2, 1),transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio__native-control:checked+.mdc-radio__background .mdc-radio__outer-circle,.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__outer-circle{transition:border-color 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio__native-control:checked+.mdc-radio__background .mdc-radio__inner-circle,.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__inner-circle{transition:transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1),border-color 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio--disabled{cursor:default;pointer-events:none}.mdc-radio__native-control:checked+.mdc-radio__background .mdc-radio__inner-circle{transform:scale(0.5);transition:transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1),border-color 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio__native-control:disabled+.mdc-radio__background,[aria-disabled=true] .mdc-radio__native-control+.mdc-radio__background{cursor:default}.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__outer-circle,[aria-disabled=true] .mdc-radio__native-control+.mdc-radio__background .mdc-radio__outer-circle{border-color:rgba(0,0,0,.26)}.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__inner-circle,[aria-disabled=true] .mdc-radio__native-control+.mdc-radio__background .mdc-radio__inner-circle{border-color:rgba(0,0,0,.26)}.mdc-radio__native-control:focus+.mdc-radio__background::before{transform:scale(2, 2);opacity:.12;transition:opacity 120ms 0ms cubic-bezier(0, 0, 0.2, 1),transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}@keyframes mdc-ripple-fg-radius-in{from{animation-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transform:translate(var(--mdc-ripple-fg-translate-start, 0)) scale(1)}to{transform:translate(var(--mdc-ripple-fg-translate-end, 0)) scale(var(--mdc-ripple-fg-scale, 1))}}@keyframes mdc-ripple-fg-opacity-in{from{animation-timing-function:linear;opacity:0}to{opacity:var(--mdc-ripple-fg-opacity, 0)}}@keyframes mdc-ripple-fg-opacity-out{from{animation-timing-function:linear;opacity:var(--mdc-ripple-fg-opacity, 0)}to{opacity:0}}.mdc-ripple-surface--test-edge-var-bug{--mdc-ripple-surface-test-edge-var: 1px solid #000;visibility:hidden}.mdc-ripple-surface--test-edge-var-bug::before{border:var(--mdc-ripple-surface-test-edge-var)}.mdc-radio{--mdc-ripple-fg-size: 0;--mdc-ripple-left: 0;--mdc-ripple-top: 0;--mdc-ripple-fg-scale: 1;--mdc-ripple-fg-translate-end: 0;--mdc-ripple-fg-translate-start: 0;-webkit-tap-highlight-color:rgba(0,0,0,0)}.mdc-radio::before,.mdc-radio::after{position:absolute;border-radius:50%;opacity:0;pointer-events:none;content:""}.mdc-radio::before{transition:opacity 15ms linear,background-color 15ms linear;z-index:1}.mdc-radio.mdc-ripple-upgraded::before{transform:scale(var(--mdc-ripple-fg-scale, 1))}.mdc-radio.mdc-ripple-upgraded::after{top:0;left:0;transform:scale(0);transform-origin:center center}.mdc-radio.mdc-ripple-upgraded--unbounded::after{top:var(--mdc-ripple-top, 0);left:var(--mdc-ripple-left, 0)}.mdc-radio.mdc-ripple-upgraded--foreground-activation::after{animation:mdc-ripple-fg-radius-in 225ms forwards,mdc-ripple-fg-opacity-in 75ms forwards}.mdc-radio.mdc-ripple-upgraded--foreground-deactivation::after{animation:mdc-ripple-fg-opacity-out 150ms;transform:translate(var(--mdc-ripple-fg-translate-end, 0)) scale(var(--mdc-ripple-fg-scale, 1))}.mdc-radio::before,.mdc-radio::after{top:calc(50% - 50%);left:calc(50% - 50%);width:100%;height:100%}.mdc-radio.mdc-ripple-upgraded::before,.mdc-radio.mdc-ripple-upgraded::after{top:var(--mdc-ripple-top, calc(50% - 50%));left:var(--mdc-ripple-left, calc(50% - 50%));width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}.mdc-radio.mdc-ripple-upgraded::after{width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}.mdc-radio::before,.mdc-radio::after{background-color:#018786}@supports not (-ms-ime-align: auto){.mdc-radio::before,.mdc-radio::after{background-color:var(--mdc-theme-secondary, #018786)}}.mdc-radio:hover::before{opacity:.04}.mdc-radio:not(.mdc-ripple-upgraded):focus::before,.mdc-radio.mdc-ripple-upgraded--background-focused::before{transition-duration:75ms;opacity:.12}.mdc-radio:not(.mdc-ripple-upgraded)::after{transition:opacity 150ms linear}.mdc-radio:not(.mdc-ripple-upgraded):active::after{transition-duration:75ms;opacity:.12}.mdc-radio.mdc-ripple-upgraded{--mdc-ripple-fg-opacity: 0.12}.mdc-radio.mdc-ripple-upgraded--background-focused .mdc-radio__background::before{content:none}:host{display:inline-block;outline:none}`; | ||
//# sourceMappingURL=mwc-radio-css.js.map |
@@ -1,20 +0,2 @@ | ||
/** | ||
@license | ||
Copyright 2018 Google Inc. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
import { FormElement, HTMLElementWithRipple } from '@material/mwc-base/form-element.js'; | ||
import MDCRadioFoundation from '@material/radio/foundation.js'; | ||
import { MDCRadioAdapter } from '@material/radio/adapter.js'; | ||
import { RadioBase } from './mwc-radio-base.js'; | ||
declare global { | ||
@@ -25,24 +7,4 @@ interface HTMLElementTagNameMap { | ||
} | ||
export declare class Radio extends FormElement { | ||
protected mdcRoot: HTMLElementWithRipple; | ||
protected formElement: HTMLInputElement; | ||
checked: boolean; | ||
disabled: boolean; | ||
value: string; | ||
name: string; | ||
protected mdcFoundationClass: typeof MDCRadioFoundation; | ||
protected mdcFoundation: MDCRadioFoundation; | ||
private _selectionController; | ||
constructor(); | ||
connectedCallback(): void; | ||
disconnectedCallback(): void; | ||
focusNative(): void; | ||
export declare class Radio extends RadioBase { | ||
static styles: import("lit-element/lib/css-tag").CSSResult; | ||
readonly ripple: import("@material/mwc-base/form-element").RippleSurface | undefined; | ||
protected createAdapter(): MDCRadioAdapter; | ||
private _changeHandler; | ||
private _focusHandler; | ||
private _clickHandler; | ||
render(): import("lit-html/lib/template-result").TemplateResult; | ||
firstUpdated(): void; | ||
} |
104
mwc-radio.js
@@ -23,106 +23,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
*/ | ||
import { FormElement, query, customElement, property, html, observer, addHasRemoveClass } from '@material/mwc-base/form-element.js'; | ||
import { customElement } from '@material/mwc-base/form-element.js'; | ||
import { RadioBase } from './mwc-radio-base.js'; | ||
import { style } from './mwc-radio-css.js'; | ||
import { SelectionController } from './selection-controller.js'; | ||
import { ripple } from '@material/mwc-ripple/ripple-directive.js'; | ||
import MDCRadioFoundation from '@material/radio/foundation.js'; | ||
let Radio = class Radio extends FormElement { | ||
constructor() { | ||
super(); | ||
this.checked = false; | ||
this.disabled = false; | ||
this.value = ''; | ||
this.name = ''; | ||
this.mdcFoundationClass = MDCRadioFoundation; | ||
this._selectionController = null; | ||
// Selection Controller is only needed for native ShadowDOM | ||
if (!window['ShadyDOM'] || !window['ShadyDOM']['inUse']) { | ||
this._selectionController = SelectionController.getController(this); | ||
} | ||
} | ||
connectedCallback() { | ||
super.connectedCallback(); | ||
if (this._selectionController) { | ||
this._selectionController.register(this); | ||
} | ||
} | ||
disconnectedCallback() { | ||
if (this._selectionController) { | ||
this._selectionController.unregister(this); | ||
} | ||
} | ||
focusNative() { | ||
this.formElement.focus(); | ||
} | ||
get ripple() { | ||
return this.mdcRoot.ripple; | ||
} | ||
createAdapter() { | ||
return Object.assign({}, addHasRemoveClass(this.mdcRoot), { setNativeControlDisabled: (disabled) => { | ||
this.formElement.disabled = disabled; | ||
} }); | ||
} | ||
_changeHandler() { | ||
this.checked = this.formElement.checked; | ||
if (this._selectionController) { | ||
this._selectionController.update(this); | ||
} | ||
} | ||
_focusHandler() { | ||
if (this._selectionController) { | ||
this._selectionController.focus(this); | ||
} | ||
} | ||
_clickHandler() { | ||
// Firefox has weird behavior with radios if they are not focused | ||
this.formElement.focus(); | ||
} | ||
render() { | ||
return html ` | ||
<div class="mdc-radio" .ripple="${ripple()}"> | ||
<input class="mdc-radio__native-control" type="radio" name="${this.name}" .checked="${this.checked}" .value="${this.value}" | ||
@change="${this._changeHandler}" | ||
@focus="${this._focusHandler}" | ||
@click="${this._clickHandler}"> | ||
<div class="mdc-radio__background"> | ||
<div class="mdc-radio__outer-circle"></div> | ||
<div class="mdc-radio__inner-circle"></div> | ||
</div> | ||
</div>`; | ||
} | ||
firstUpdated() { | ||
super.firstUpdated(); | ||
if (this._selectionController) { | ||
this._selectionController.update(this); | ||
} | ||
} | ||
let Radio = class Radio extends RadioBase { | ||
}; | ||
Radio.styles = style; | ||
__decorate([ | ||
query('.mdc-radio') | ||
], Radio.prototype, "mdcRoot", void 0); | ||
__decorate([ | ||
query('input') | ||
], Radio.prototype, "formElement", void 0); | ||
__decorate([ | ||
property({ type: Boolean }), | ||
observer(function (checked) { | ||
this.formElement.checked = checked; | ||
}) | ||
], Radio.prototype, "checked", void 0); | ||
__decorate([ | ||
property({ type: Boolean }), | ||
observer(function (disabled) { | ||
this.mdcFoundation.setDisabled(disabled); | ||
}) | ||
], Radio.prototype, "disabled", void 0); | ||
__decorate([ | ||
property({ type: String }), | ||
observer(function (value) { | ||
this.formElement.value = value; | ||
}) | ||
], Radio.prototype, "value", void 0); | ||
__decorate([ | ||
property({ type: String }) | ||
], Radio.prototype, "name", void 0); | ||
Radio = __decorate([ | ||
@@ -129,0 +31,0 @@ customElement('mwc-radio') |
{ | ||
"name": "@material/mwc-radio", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "", | ||
@@ -8,3 +8,4 @@ "main": "mwc-radio.js", | ||
"type": "git", | ||
"url": "https://github.com/material-components/material-components-web-components.git" | ||
"url": "https://github.com/material-components/material-components-web-components.git", | ||
"directory": "packages/radio" | ||
}, | ||
@@ -17,5 +18,5 @@ "scripts": { | ||
"dependencies": { | ||
"@material/mwc-base": "^0.6.0", | ||
"@material/mwc-ripple": "^0.6.0", | ||
"@material/radio": "^1.0.0" | ||
"@material/mwc-base": "^0.7.0", | ||
"@material/mwc-ripple": "^0.7.0", | ||
"@material/radio": "^3.0.0" | ||
}, | ||
@@ -25,3 +26,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "1961a2530cc20bc020bba88f4da76d085ad1f1e0" | ||
"gitHead": "c8c5d01ad2103af63e3d7656b5d1acc5ccaa05db" | ||
} |
@@ -1,64 +0,81 @@ | ||
# mwc-radio | ||
# `<mwc-radio>` [![Published on npm](https://img.shields.io/npm/v/@material/mwc-radio.svg)](https://www.npmjs.com/package/@material/mwc-radio) | ||
> :warning: These components are a work in progress. They are pre-release and should be considered experimental, as they may undergo major changes before release. We are experimenting with alternate architectures and approaches with the goal of allowing us to bring the most correct and optimal implementation of Material components to the widest possible audiences. Visible progress may be slow, as this research is across teams and repositories so is not consistently reflected in commits to this codebase. :warning: | ||
> IMPORTANT: The Material Web Components are a work in progress and subject to | ||
> major changes until 1.0 release. | ||
A [Material Components](https://material.io/components/) icon implementation using [Web Components](https://www.webcomponents.org/introduction) | ||
Radio buttons allow the user to select one option from a set. Use radio buttons when the user needs to see all available options. | ||
## Getting started | ||
<img src="https://raw.githubusercontent.com/material-components/material-components-web-components/c8c5d01ad2103af63e3d7656b5d1acc5ccaa05db/packages/radio/images/standard.png" width="84px" height="48px"> | ||
* The easiest way to try out mwc-radio is to use one of these online tools: | ||
[Material Design Guidelines: Radio buttons](https://material.io/design/components/selection-controls.html#radio-buttons) | ||
* Runs in all [supported](#supported-browsers) browsers: [StackBlitz](https://stackblitz.com/edit/mwc-icon-example?file=index.js), [Glitch](https://glitch.com/edit/#!/mwc-icon-example?path=index.html) | ||
## Installation | ||
* Runs in browsers with [JavaScript Modules](https://caniuse.com/#search=modules): [JSBin](http://jsbin.com/qibisux/edit?html,output), | ||
[CodePen](https://codepen.io/azakus/pen/deZLja). | ||
```sh | ||
npm install @material/mwc-radio | ||
``` | ||
* You can also copy [this HTML file](https://gist.githubusercontent.com/azakus/f01e9fc2ed04e781ad5a52ded7b296e7/raw/266f2f4f91cbfe89b2acc6ec63957b1a3cfe9b39/index.html) into a local file and run it in any browser that supports [JavaScript Modules]((https://caniuse.com/#search=modules)). | ||
> NOTE: The Material Web Components are distributed as ES2017 JavaScript | ||
> Modules, and use the Custom Elements API. They are compatible with all modern | ||
> browsers including Chrome, Firefox, Safari, Edge, and IE11, but an additional | ||
> tooling step is required to resolve *bare module specifiers*, as well as | ||
> transpilation and polyfills for Edge and IE11. See | ||
> [here](https://github.com/material-components/material-components-web-components#quick-start) | ||
> for detailed instructions. | ||
* When you're ready to use mwc-radio in a project, install it via [npm](https://www.npmjs.com/). To run the project in the browser, a module-compatible toolctain is required. We recommend installing the [Polymer CLI](https://github.com/Polymer/polymer-cli) and using its development server as follows. | ||
## Example usage | ||
1. Ensure the webcomponents polyfills are included in your HTML page | ||
### Standard | ||
- Install webcomponents polyfills | ||
<img src="https://raw.githubusercontent.com/material-components/material-components-web-components/c8c5d01ad2103af63e3d7656b5d1acc5ccaa05db/packages/radio/images/standard.png" width="84px" height="48px"> | ||
```npm i @webcomponents/webcomponentsjs``` | ||
```html | ||
<mwc-radio name="myGroup" value="value1"></mwc-radio> | ||
<mwc-radio name="myGroup" value="value2" checked></mwc-radio> | ||
- Add webcomponents polyfills to your HTML page | ||
<script type="module"> | ||
import '@material/mwc-radio'; | ||
</script> | ||
``` | ||
```<script src="@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>``` | ||
### Custom color | ||
1. Add mwc-radio to your project: | ||
<img src="https://raw.githubusercontent.com/material-components/material-components-web-components/c8c5d01ad2103af63e3d7656b5d1acc5ccaa05db/packages/radio/images/custom_color.png" width="84px" height="48px"> | ||
```npm i @material/mwc-radio``` | ||
```css | ||
mwc-radio { | ||
--mdc-theme-secondary: #ff4081; | ||
} | ||
``` | ||
1. Import the mwc-radio definition into your HTML page: | ||
## API | ||
```<script type="module" src="@material/mwc-radio/index.js"></script>``` | ||
### Slots | ||
*None* | ||
Or into your module script: | ||
### Properties/Attributes | ||
```import {Radio} from "@material/mwc-radio"``` | ||
| Name | Type | Default | Description | ||
| --------------- | --------- |-------- | ----------- | ||
| `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. | ||
| `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. | ||
| `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. | ||
| `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. | ||
1. Create an instance of mwc-radio in your HTML page, or via any framework that [supports rendering Custom Elements](https://custom-elements-everywhere.com/): | ||
### Methods | ||
*None* | ||
```<mwc-radio></mwc-radio>``` | ||
### Events | ||
| Name | Detail | Description | ||
| ---------| ------ | ----------- | ||
| `change` | `{}` | Indicates that the radio button's `checked` state has changed. | ||
1. Install the Polymer CLI: | ||
### CSS Custom Properties | ||
```npm i -g polymer-cli``` | ||
| Name | Default | Description | ||
| ----------------------- | -------------------------------------- |------------ | ||
| `--mdc-theme-secondary` | ![](https://raw.githubusercontent.com/material-components/material-components-web-components/c8c5d01ad2103af63e3d7656b5d1acc5ccaa05db/packages/radio/images/color_018786.png) `#018786` | Color of the radio button. | ||
1. Run the development server and open a browser pointing to its URL: | ||
## Additional references | ||
```polymer serve``` | ||
> mwc-radio is published on [npm](https://www.npmjs.com/package/@material/mwc-radio) using JavaScript Modules. | ||
This means it can take advantage of the standard native JavaScript module loader available in all current major browsers. | ||
> | ||
> However, since mwc-radio uses npm convention to reference dependencies by name, a light transform to rewrite specifiers to URLs is required to get it to run in the browser. The polymer-cli's development server `polymer serve` automatically handles this transform. | ||
Tools like [WebPack](https://webpack.js.org/) and [Rollup](https://rollupjs.org/) can also be used to serve and/or bundle mwc-radio. | ||
## Supported Browsers | ||
The last 2 versions of all modern browsers are supported, including | ||
Chrome, Safari, Opera, Firefox, Edge. In addition, Internet Explorer 11 is also supported. | ||
- [MDC Web: Radio Buttons](https://material.io/develop/web/components/input-controls/radio-buttons/) |
@@ -19,2 +19,2 @@ /** | ||
export const style = css`.mdc-radio{display:inline-block;position:relative;flex:0 0 auto;box-sizing:border-box;width:40px;height:40px;padding:10px;cursor:pointer;will-change:opacity,transform,border-color,color}.mdc-radio .mdc-radio__native-control:enabled:not(:checked)+.mdc-radio__background .mdc-radio__outer-circle{border-color:rgba(0,0,0,.54)}.mdc-radio .mdc-radio__native-control:enabled:checked+.mdc-radio__background .mdc-radio__outer-circle{border-color:#018786;border-color:var(--mdc-theme-secondary, #018786)}.mdc-radio .mdc-radio__native-control:enabled+.mdc-radio__background .mdc-radio__inner-circle{border-color:#018786;border-color:var(--mdc-theme-secondary, #018786)}.mdc-radio .mdc-radio__background::before{background-color:#018786}@supports not (-ms-ime-align: auto){.mdc-radio .mdc-radio__background::before{background-color:var(--mdc-theme-secondary, #018786)}}.mdc-radio__background{display:inline-block;position:absolute;left:10px;box-sizing:border-box;width:50%;height:50%}.mdc-radio__background::before{position:absolute;top:0;left:0;width:100%;height:100%;transform:scale(0, 0);border-radius:50%;opacity:0;pointer-events:none;content:"";transition:opacity 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1),transform 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1)}.mdc-radio__outer-circle{position:absolute;top:0;left:0;box-sizing:border-box;width:100%;height:100%;border-width:2px;border-style:solid;border-radius:50%;transition:border-color 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1)}.mdc-radio__inner-circle{position:absolute;top:0;left:0;box-sizing:border-box;width:100%;height:100%;transform:scale(0, 0);border-width:10px;border-style:solid;border-radius:50%;transition:transform 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1),border-color 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1)}.mdc-radio__native-control{position:absolute;top:0;left:0;width:100%;height:100%;margin:0;padding:0;opacity:0;cursor:inherit;z-index:1}.mdc-radio__native-control:checked+.mdc-radio__background,.mdc-radio__native-control:disabled+.mdc-radio__background{transition:opacity 120ms 0ms cubic-bezier(0, 0, 0.2, 1),transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio__native-control:checked+.mdc-radio__background .mdc-radio__outer-circle,.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__outer-circle{transition:border-color 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio__native-control:checked+.mdc-radio__background .mdc-radio__inner-circle,.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__inner-circle{transition:transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1),border-color 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio--disabled{cursor:default;pointer-events:none}.mdc-radio__native-control:checked+.mdc-radio__background .mdc-radio__inner-circle{transform:scale(0.5);transition:transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1),border-color 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio__native-control:disabled+.mdc-radio__background,[aria-disabled=true] .mdc-radio__native-control+.mdc-radio__background{cursor:default}.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__outer-circle,[aria-disabled=true] .mdc-radio__native-control+.mdc-radio__background .mdc-radio__outer-circle{border-color:rgba(0,0,0,.26)}.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__inner-circle,[aria-disabled=true] .mdc-radio__native-control+.mdc-radio__background .mdc-radio__inner-circle{border-color:rgba(0,0,0,.26)}.mdc-radio__native-control:focus+.mdc-radio__background::before{transform:scale(2, 2);opacity:.12;transition:opacity 120ms 0ms cubic-bezier(0, 0, 0.2, 1),transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}@keyframes mdc-ripple-fg-radius-in{from{animation-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transform:translate(var(--mdc-ripple-fg-translate-start, 0)) scale(1)}to{transform:translate(var(--mdc-ripple-fg-translate-end, 0)) scale(var(--mdc-ripple-fg-scale, 1))}}@keyframes mdc-ripple-fg-opacity-in{from{animation-timing-function:linear;opacity:0}to{opacity:var(--mdc-ripple-fg-opacity, 0)}}@keyframes mdc-ripple-fg-opacity-out{from{animation-timing-function:linear;opacity:var(--mdc-ripple-fg-opacity, 0)}to{opacity:0}}.mdc-ripple-surface--test-edge-var-bug{--mdc-ripple-surface-test-edge-var: 1px solid #000;visibility:hidden}.mdc-ripple-surface--test-edge-var-bug::before{border:var(--mdc-ripple-surface-test-edge-var)}.mdc-radio{--mdc-ripple-fg-size: 0;--mdc-ripple-left: 0;--mdc-ripple-top: 0;--mdc-ripple-fg-scale: 1;--mdc-ripple-fg-translate-end: 0;--mdc-ripple-fg-translate-start: 0;-webkit-tap-highlight-color:rgba(0,0,0,0);will-change:transform,opacity}.mdc-radio::before,.mdc-radio::after{position:absolute;border-radius:50%;opacity:0;pointer-events:none;content:""}.mdc-radio::before{transition:opacity 15ms linear,background-color 15ms linear;z-index:1}.mdc-radio.mdc-ripple-upgraded::before{transform:scale(var(--mdc-ripple-fg-scale, 1))}.mdc-radio.mdc-ripple-upgraded::after{top:0;left:0;transform:scale(0);transform-origin:center center}.mdc-radio.mdc-ripple-upgraded--unbounded::after{top:var(--mdc-ripple-top, 0);left:var(--mdc-ripple-left, 0)}.mdc-radio.mdc-ripple-upgraded--foreground-activation::after{animation:mdc-ripple-fg-radius-in 225ms forwards,mdc-ripple-fg-opacity-in 75ms forwards}.mdc-radio.mdc-ripple-upgraded--foreground-deactivation::after{animation:mdc-ripple-fg-opacity-out 150ms;transform:translate(var(--mdc-ripple-fg-translate-end, 0)) scale(var(--mdc-ripple-fg-scale, 1))}.mdc-radio::before,.mdc-radio::after{top:calc(50% - 50%);left:calc(50% - 50%);width:100%;height:100%}.mdc-radio.mdc-ripple-upgraded::before,.mdc-radio.mdc-ripple-upgraded::after{top:var(--mdc-ripple-top, calc(50% - 50%));left:var(--mdc-ripple-left, calc(50% - 50%));width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}.mdc-radio.mdc-ripple-upgraded::after{width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}.mdc-radio::before,.mdc-radio::after{background-color:#018786}@supports not (-ms-ime-align: auto){.mdc-radio::before,.mdc-radio::after{background-color:var(--mdc-theme-secondary, #018786)}}.mdc-radio:hover::before{opacity:.04}.mdc-radio:not(.mdc-ripple-upgraded):focus::before,.mdc-radio.mdc-ripple-upgraded--background-focused::before{transition-duration:75ms;opacity:.12}.mdc-radio:not(.mdc-ripple-upgraded)::after{transition:opacity 150ms linear}.mdc-radio:not(.mdc-ripple-upgraded):active::after{transition-duration:75ms;opacity:.12}.mdc-radio.mdc-ripple-upgraded{--mdc-ripple-fg-opacity: 0.12}.mdc-radio.mdc-ripple-upgraded--background-focused .mdc-radio__background::before{content:none}:host{display:inline-block;outline:none}`; | ||
export const style = css`.mdc-radio{display:inline-block;position:relative;flex:0 0 auto;box-sizing:border-box;width:40px;height:40px;padding:10px;cursor:pointer;will-change:opacity,transform,border-color,color}.mdc-radio .mdc-radio__native-control:enabled:not(:checked)+.mdc-radio__background .mdc-radio__outer-circle{border-color:rgba(0,0,0,.54)}.mdc-radio .mdc-radio__native-control:enabled:checked+.mdc-radio__background .mdc-radio__outer-circle{border-color:#018786;border-color:var(--mdc-theme-secondary, #018786)}.mdc-radio .mdc-radio__native-control:enabled+.mdc-radio__background .mdc-radio__inner-circle{border-color:#018786;border-color:var(--mdc-theme-secondary, #018786)}.mdc-radio .mdc-radio__background::before{background-color:#018786}@supports not (-ms-ime-align: auto){.mdc-radio .mdc-radio__background::before{background-color:var(--mdc-theme-secondary, #018786)}}.mdc-radio__background{display:inline-block;position:absolute;left:10px;box-sizing:border-box;width:50%;height:50%}.mdc-radio__background::before{position:absolute;top:0;left:0;width:100%;height:100%;transform:scale(0, 0);border-radius:50%;opacity:0;pointer-events:none;content:"";transition:opacity 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1),transform 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1)}.mdc-radio__outer-circle{position:absolute;top:0;left:0;box-sizing:border-box;width:100%;height:100%;border-width:2px;border-style:solid;border-radius:50%;transition:border-color 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1)}.mdc-radio__inner-circle{position:absolute;top:0;left:0;box-sizing:border-box;width:100%;height:100%;transform:scale(0, 0);border-width:10px;border-style:solid;border-radius:50%;transition:transform 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1),border-color 120ms 0ms cubic-bezier(0.4, 0, 0.6, 1)}.mdc-radio__native-control{position:absolute;top:0;left:0;width:100%;height:100%;margin:0;padding:0;opacity:0;cursor:inherit;z-index:1}.mdc-radio__native-control:checked+.mdc-radio__background,.mdc-radio__native-control:disabled+.mdc-radio__background{transition:opacity 120ms 0ms cubic-bezier(0, 0, 0.2, 1),transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio__native-control:checked+.mdc-radio__background .mdc-radio__outer-circle,.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__outer-circle{transition:border-color 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio__native-control:checked+.mdc-radio__background .mdc-radio__inner-circle,.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__inner-circle{transition:transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1),border-color 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio--disabled{cursor:default;pointer-events:none}.mdc-radio__native-control:checked+.mdc-radio__background .mdc-radio__inner-circle{transform:scale(0.5);transition:transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1),border-color 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-radio__native-control:disabled+.mdc-radio__background,[aria-disabled=true] .mdc-radio__native-control+.mdc-radio__background{cursor:default}.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__outer-circle,[aria-disabled=true] .mdc-radio__native-control+.mdc-radio__background .mdc-radio__outer-circle{border-color:rgba(0,0,0,.26)}.mdc-radio__native-control:disabled+.mdc-radio__background .mdc-radio__inner-circle,[aria-disabled=true] .mdc-radio__native-control+.mdc-radio__background .mdc-radio__inner-circle{border-color:rgba(0,0,0,.26)}.mdc-radio__native-control:focus+.mdc-radio__background::before{transform:scale(2, 2);opacity:.12;transition:opacity 120ms 0ms cubic-bezier(0, 0, 0.2, 1),transform 120ms 0ms cubic-bezier(0, 0, 0.2, 1)}@keyframes mdc-ripple-fg-radius-in{from{animation-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transform:translate(var(--mdc-ripple-fg-translate-start, 0)) scale(1)}to{transform:translate(var(--mdc-ripple-fg-translate-end, 0)) scale(var(--mdc-ripple-fg-scale, 1))}}@keyframes mdc-ripple-fg-opacity-in{from{animation-timing-function:linear;opacity:0}to{opacity:var(--mdc-ripple-fg-opacity, 0)}}@keyframes mdc-ripple-fg-opacity-out{from{animation-timing-function:linear;opacity:var(--mdc-ripple-fg-opacity, 0)}to{opacity:0}}.mdc-ripple-surface--test-edge-var-bug{--mdc-ripple-surface-test-edge-var: 1px solid #000;visibility:hidden}.mdc-ripple-surface--test-edge-var-bug::before{border:var(--mdc-ripple-surface-test-edge-var)}.mdc-radio{--mdc-ripple-fg-size: 0;--mdc-ripple-left: 0;--mdc-ripple-top: 0;--mdc-ripple-fg-scale: 1;--mdc-ripple-fg-translate-end: 0;--mdc-ripple-fg-translate-start: 0;-webkit-tap-highlight-color:rgba(0,0,0,0)}.mdc-radio::before,.mdc-radio::after{position:absolute;border-radius:50%;opacity:0;pointer-events:none;content:""}.mdc-radio::before{transition:opacity 15ms linear,background-color 15ms linear;z-index:1}.mdc-radio.mdc-ripple-upgraded::before{transform:scale(var(--mdc-ripple-fg-scale, 1))}.mdc-radio.mdc-ripple-upgraded::after{top:0;left:0;transform:scale(0);transform-origin:center center}.mdc-radio.mdc-ripple-upgraded--unbounded::after{top:var(--mdc-ripple-top, 0);left:var(--mdc-ripple-left, 0)}.mdc-radio.mdc-ripple-upgraded--foreground-activation::after{animation:mdc-ripple-fg-radius-in 225ms forwards,mdc-ripple-fg-opacity-in 75ms forwards}.mdc-radio.mdc-ripple-upgraded--foreground-deactivation::after{animation:mdc-ripple-fg-opacity-out 150ms;transform:translate(var(--mdc-ripple-fg-translate-end, 0)) scale(var(--mdc-ripple-fg-scale, 1))}.mdc-radio::before,.mdc-radio::after{top:calc(50% - 50%);left:calc(50% - 50%);width:100%;height:100%}.mdc-radio.mdc-ripple-upgraded::before,.mdc-radio.mdc-ripple-upgraded::after{top:var(--mdc-ripple-top, calc(50% - 50%));left:var(--mdc-ripple-left, calc(50% - 50%));width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}.mdc-radio.mdc-ripple-upgraded::after{width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}.mdc-radio::before,.mdc-radio::after{background-color:#018786}@supports not (-ms-ime-align: auto){.mdc-radio::before,.mdc-radio::after{background-color:var(--mdc-theme-secondary, #018786)}}.mdc-radio:hover::before{opacity:.04}.mdc-radio:not(.mdc-ripple-upgraded):focus::before,.mdc-radio.mdc-ripple-upgraded--background-focused::before{transition-duration:75ms;opacity:.12}.mdc-radio:not(.mdc-ripple-upgraded)::after{transition:opacity 150ms linear}.mdc-radio:not(.mdc-ripple-upgraded):active::after{transition-duration:75ms;opacity:.12}.mdc-radio.mdc-ripple-upgraded{--mdc-ripple-fg-opacity: 0.12}.mdc-radio.mdc-ripple-upgraded--background-focused .mdc-radio__background::before{content:none}:host{display:inline-block;outline:none}`; |
@@ -17,8 +17,6 @@ /** | ||
*/ | ||
import {FormElement, query, customElement, property, html, observer, HTMLElementWithRipple, addHasRemoveClass} from '@material/mwc-base/form-element.js'; | ||
import {customElement} from '@material/mwc-base/form-element.js'; | ||
import {RadioBase} from './mwc-radio-base.js'; | ||
import {style} from './mwc-radio-css.js'; | ||
import {SelectionController} from './selection-controller.js'; | ||
import {ripple} from '@material/mwc-ripple/ripple-directive.js'; | ||
import MDCRadioFoundation from '@material/radio/foundation.js'; | ||
import {MDCRadioAdapter} from '@material/radio/adapter.js'; | ||
@@ -31,116 +29,5 @@ declare global { | ||
@customElement('mwc-radio' as any) | ||
export class Radio extends FormElement { | ||
@query('.mdc-radio') | ||
protected mdcRoot!: HTMLElementWithRipple; | ||
@query('input') | ||
protected formElement!: HTMLInputElement | ||
@property({type: Boolean}) | ||
@observer(function(this: Radio, checked: boolean) { | ||
this.formElement.checked = checked; | ||
}) | ||
checked = false; | ||
@property({type: Boolean}) | ||
@observer(function(this: Radio, disabled: boolean) { | ||
this.mdcFoundation.setDisabled(disabled); | ||
}) | ||
disabled = false; | ||
@property({type: String}) | ||
@observer(function(this: Radio, value: string) { | ||
this.formElement.value = value; | ||
}) | ||
value = ''; | ||
@property({type: String}) | ||
name = ''; | ||
protected mdcFoundationClass = MDCRadioFoundation; | ||
protected mdcFoundation!: MDCRadioFoundation; | ||
private _selectionController: SelectionController | null = null; | ||
constructor() { | ||
super(); | ||
// Selection Controller is only needed for native ShadowDOM | ||
if (!window['ShadyDOM'] || !window['ShadyDOM']['inUse']) { | ||
this._selectionController = SelectionController.getController(this); | ||
} | ||
} | ||
connectedCallback() { | ||
super.connectedCallback(); | ||
if (this._selectionController) { | ||
this._selectionController.register(this); | ||
} | ||
} | ||
disconnectedCallback() { | ||
if (this._selectionController) { | ||
this._selectionController.unregister(this); | ||
} | ||
} | ||
focusNative() { | ||
this.formElement.focus(); | ||
} | ||
@customElement('mwc-radio') | ||
export class Radio extends RadioBase { | ||
static styles = style; | ||
get ripple() { | ||
return this.mdcRoot.ripple; | ||
} | ||
protected createAdapter(): MDCRadioAdapter { | ||
return { | ||
...addHasRemoveClass(this.mdcRoot), | ||
setNativeControlDisabled: (disabled: boolean) => { | ||
this.formElement.disabled = disabled; | ||
} | ||
}; | ||
} | ||
private _changeHandler() { | ||
this.checked = this.formElement.checked; | ||
if (this._selectionController) { | ||
this._selectionController.update(this); | ||
} | ||
} | ||
private _focusHandler() { | ||
if (this._selectionController) { | ||
this._selectionController.focus(this); | ||
} | ||
} | ||
private _clickHandler() { | ||
// Firefox has weird behavior with radios if they are not focused | ||
this.formElement.focus(); | ||
} | ||
render() { | ||
return html` | ||
<div class="mdc-radio" .ripple="${ripple()}"> | ||
<input class="mdc-radio__native-control" type="radio" name="${this.name}" .checked="${this.checked}" .value="${this.value}" | ||
@change="${this._changeHandler}" | ||
@focus="${this._focusHandler}" | ||
@click="${this._clickHandler}"> | ||
<div class="mdc-radio__background"> | ||
<div class="mdc-radio__outer-circle"></div> | ||
<div class="mdc-radio__inner-circle"></div> | ||
</div> | ||
</div>`; | ||
} | ||
firstUpdated() { | ||
super.firstUpdated(); | ||
if (this._selectionController) { | ||
this._selectionController.update(this); | ||
} | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
797
82
82297
16
2
+ Added@material/animation@3.1.0(transitive)
+ Added@material/base@3.1.0(transitive)
+ Added@material/dom@3.1.0(transitive)
+ Added@material/feature-targeting@3.1.0(transitive)
+ Added@material/mwc-base@0.7.0(transitive)
+ Added@material/mwc-ripple@0.7.1(transitive)
+ Added@material/radio@3.2.0(transitive)
+ Added@material/ripple@3.2.0(transitive)
+ Added@material/theme@3.1.0(transitive)
- Removed@material/animation@1.0.0(transitive)
- Removed@material/base@1.0.0(transitive)
- Removed@material/dom@1.1.0(transitive)
- Removed@material/feature-targeting@0.44.1(transitive)
- Removed@material/mwc-base@0.6.0(transitive)
- Removed@material/mwc-ripple@0.6.0(transitive)
- Removed@material/radio@1.1.0(transitive)
- Removed@material/ripple@1.1.0(transitive)
- Removed@material/theme@1.1.0(transitive)
Updated@material/mwc-base@^0.7.0
Updated@material/mwc-ripple@^0.7.0
Updated@material/radio@^3.0.0