11import { LitElement , html , CSSResultGroup } from 'lit' ;
22import { property } from 'lit/decorators.js' ;
33import componentStyles from '../../styles/component.styles.js' ;
4+ import { dispatchEvent } from '../../internals/event' ;
45import styles from './input-stepper.styles.js' ;
56
67/**
@@ -17,22 +18,22 @@ export default class InputStepper extends LitElement {
1718 static formAssociated = true ;
1819 private readonly _internals : ElementInternals ;
1920
20- @property ( { type : String } )
21+ @property ( )
2122 name = '' ;
2223
23- @property ( { type : Number , reflect : true } )
24+ @property ( { type : Number } )
2425 value = 1 ;
2526
26- @property ( { type : Number , reflect : true } )
27+ @property ( { type : Number } )
2728 min = 0 ;
2829
29- @property ( { type : Number , reflect : true } )
30+ @property ( { type : Number } )
3031 max = Infinity ;
3132
32- @property ( { type : Number , reflect : true } )
33+ @property ( { type : Number } )
3334 step = 1 ;
3435
35- @property ( { type : Boolean , reflect : true } )
36+ @property ( { type : Boolean } )
3637 disabled = false ;
3738
3839 constructor ( ) {
@@ -51,6 +52,7 @@ export default class InputStepper extends LitElement {
5152 newValue ( val : number ) {
5253 this . value = Math . min ( Math . max ( val , this . min ) , this . max ) ;
5354 this . _internals . setFormValue ( String ( this . value ) ) ;
55+ dispatchEvent ( this , 'change' , { value : this . value } ) ;
5456 }
5557
5658 /**
@@ -74,6 +76,14 @@ export default class InputStepper extends LitElement {
7476 this . inputElement ?. click ( ) ;
7577 }
7678
79+ /**
80+ * When user clicks up/down arrows or enter a valid number.
81+ */
82+ private handleChange ( event : Event ) {
83+ const input = event . target as HTMLInputElement ;
84+ this . newValue ( Number ( input . value ) ) ;
85+ }
86+
7787 render ( ) {
7888 return html `< div class ="stepper ">
7989 < button
@@ -87,6 +97,7 @@ export default class InputStepper extends LitElement {
8797 type ="number "
8898 .disabled ="${ this . disabled } "
8999 .value ="${ String ( this . value ) } "
100+ @change ="${ this . handleChange } "
90101 min ="${ this . min } "
91102 max ="${ this . max } "
92103 />
0 commit comments