This repository has been archived by the owner on Jul 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
v-checkbox.js
118 lines (103 loc) · 2.77 KB
/
v-checkbox.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { PolymerElement, html } from '@polymer/polymer';
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin';
import { ActiveMixin } from './mixins/active-mixin.js';
import { CheckedMixin } from './mixins/checked-mixin.js';
import { InputAriaMixin } from './mixins/input-aria-mixin.js';
import { SlotLabelMixin } from './mixins/slot-label-mixin.js';
export class VCheckbox extends SlotLabelMixin(
CheckedMixin(InputAriaMixin(ActiveMixin(ThemableMixin(PolymerElement))))
) {
static get is() {
return 'vaadin-checkbox';
}
static get template() {
return html`
<style>
:host {
display: inline-block;
}
:host([hidden]) {
display: none !important;
}
[part='container'] {
display: inline-flex;
align-items: baseline;
}
/* visually hidden */
::slotted(input) {
border: 0px;
clip: rect(0px, 0px, 0px, 0px);
clip-path: inset(50%);
height: 1px;
margin: 0px -1px -1px 0px;
overflow: hidden;
padding: 0px;
position: absolute;
width: 1px;
white-space: nowrap;
}
</style>
<div part="container">
<div part="checkbox">
<slot name="input"></slot>
</div>
<div part="label">
<slot name="label"></slot>
</div>
<div style="display: none !important">
<slot id="noop"></slot>
</div>
</div>
`;
}
static get properties() {
return {
/**
* Indeterminate state of the checkbox when it's neither checked nor unchecked, but undetermined.
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#Indeterminate_state_checkboxes
* @type {boolean}
*/
indeterminate: {
type: Boolean,
notify: true,
observer: '_indeterminateChanged',
reflectToAttribute: true,
value: false
}
};
}
get _noopSlot() {
return this.$.noop;
}
constructor() {
super();
this._setType('checkbox');
this.value = 'on';
}
connectedCallback() {
super.connectedCallback();
if (this._inputNode) {
this._inputNode.indeterminate = this.indeterminate;
}
}
/** @private */
_indeterminateChanged(indeterminate) {
if (indeterminate && this._inputNode) {
this._inputNode.indeterminate = indeterminate;
}
}
/** @protected */
_toggleChecked() {
this.indeterminate = false;
super._toggleChecked();
}
/** @protected */
_toggleAriaChecked() {
if (this.indeterminate) {
this.setAttribute('aria-checked', 'mixed');
} else {
this.setAttribute('aria-checked', Boolean(this.checked));
}
}
}
customElements.define(VCheckbox.is, VCheckbox);