File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,10 @@ import {
23
23
getValidityAnchor ,
24
24
mixinConstraintValidation ,
25
25
} from '../../labs/behaviors/constraint-validation.js' ;
26
- import { mixinElementInternals } from '../../labs/behaviors/element-internals.js' ;
26
+ import {
27
+ internals ,
28
+ mixinElementInternals ,
29
+ } from '../../labs/behaviors/element-internals.js' ;
27
30
import {
28
31
getFormState ,
29
32
getFormValue ,
@@ -111,6 +114,12 @@ export class Checkbox extends checkboxBaseClass {
111
114
this . prevDisabled = changed . get ( 'disabled' ) ?? this . disabled ;
112
115
this . prevIndeterminate =
113
116
changed . get ( 'indeterminate' ) ?? this . indeterminate ;
117
+
118
+ if ( this . checked ) {
119
+ this [ internals ] . states . add ( 'checked' ) ;
120
+ } else {
121
+ this [ internals ] . states . delete ( 'checked' ) ;
122
+ }
114
123
}
115
124
116
125
super . update ( changed ) ;
Original file line number Diff line number Diff line change @@ -50,13 +50,15 @@ describe('checkbox', () => {
50
50
expect ( harness . element . indeterminate ) . toEqual ( false ) ;
51
51
expect ( harness . element . disabled ) . toEqual ( false ) ;
52
52
expect ( harness . element . value ) . toEqual ( 'on' ) ;
53
+ expect ( harness . element . matches ( ':state(checked)' ) ) . toEqual ( false ) ;
53
54
} ) ;
54
55
55
56
it ( 'user input updates checked state' , async ( ) => {
56
57
const { harness} = await setupTest ( ) ;
57
58
await harness . clickWithMouse ( ) ;
58
59
await env . waitForStability ( ) ;
59
60
expect ( harness . element . checked ) . toEqual ( true ) ;
61
+ expect ( harness . element . matches ( ':state(checked)' ) ) . toEqual ( true ) ;
60
62
} ) ;
61
63
62
64
it ( 'should trigger changed event when checkbox is selected' , async ( ) => {
Original file line number Diff line number Diff line change @@ -209,3 +209,9 @@ Token | Default value
209
209
<!-- mdformat on(autogenerated might break rendering in catalog) -->
210
210
211
211
<!-- auto-generated API docs end -->
212
+
213
+ #### States
214
+
215
+ | State | Description |
216
+ | --- | --- |
217
+ | ` checked ` | Set if this checkbox is checked. |
You can’t perform that action at this time.
0 commit comments