File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,18 @@ export default class AutoCheckElement extends HTMLElement {
40
40
input . setCustomValidity ( '' )
41
41
}
42
42
43
+ attributeChangedCallback ( name : string ) {
44
+ if ( name === 'required' ) {
45
+ const input = this . input
46
+ if ( ! input ) return
47
+ input . required = this . required
48
+ }
49
+ }
50
+
51
+ static get observedAttributes ( ) : Array < string > {
52
+ return [ 'required' ]
53
+ }
54
+
43
55
get input ( ) : ?HTMLInputElement {
44
56
const input = this . querySelector ( 'input ')
45
57
return input instanceof HTMLInputElement ? input : null
@@ -71,10 +83,6 @@ export default class AutoCheckElement extends HTMLElement {
71
83
}
72
84
73
85
set required ( required : boolean ) {
74
- const input = this . input
75
- if ( ! input ) return
76
-
77
- input . required = required
78
86
if ( required ) {
79
87
this . setAttribute ( 'required' , '' )
80
88
} else {
Original file line number Diff line number Diff line change @@ -40,8 +40,7 @@ describe('auto-check element', function() {
40
40
} )
41
41
42
42
it ( 'invalidates empty input' , function ( ) {
43
- // FIXME Must implement attributeChanged callback.
44
- checker . required = true
43
+ assert . isTrue ( input . hasAttribute ( 'required' ) )
45
44
assert . isFalse ( input . checkValidity ( ) )
46
45
} )
47
46
You can’t perform that action at this time.
0 commit comments