@@ -43,18 +43,10 @@ export default class PgInputNumber extends HTMLElement {
4343 this . #triggerInput( this . value + this . step ) ;
4444 } ) ;
4545 this . $buttonMinus . addEventListener ( 'finish' , ( e : any ) => {
46- this . dispatchEvent ( new CustomEvent ( 'change' , {
47- detail : {
48- value : this . value ,
49- } ,
50- } ) ) ;
46+ this . #triggerChange( this . value ) ;
5147 } ) ;
5248 this . $buttonPlus . addEventListener ( 'finish' , ( e : any ) => {
53- this . dispatchEvent ( new CustomEvent ( 'change' , {
54- detail : {
55- value : this . value ,
56- } ,
57- } ) ) ;
49+ this . #triggerChange( this . value ) ;
5850 } ) ;
5951 }
6052
@@ -64,6 +56,12 @@ export default class PgInputNumber extends HTMLElement {
6456 if ( changes . value && ! this . skipValue ) {
6557 this . $input . value = `${ this . value } ` ;
6658 }
59+ if ( changes . min ) {
60+ this . $input . min = `${ this . min } ` ;
61+ }
62+ if ( changes . max ) {
63+ this . $input . max = `${ this . max } ` ;
64+ }
6765 if ( changes . placeholder ) {
6866 this . $input . placeholder = this . placeholder ;
6967 }
@@ -74,6 +72,9 @@ export default class PgInputNumber extends HTMLElement {
7472 }
7573
7674 #triggerInput( value ) {
75+ if ( value < this . min || value > this . max ) {
76+ return ;
77+ }
7778 this . dispatchEvent (
7879 new CustomEvent ( 'input' , {
7980 detail : {
@@ -91,14 +92,21 @@ export default class PgInputNumber extends HTMLElement {
9192 this . #triggerInput( value ) ;
9293 }
9394
94- handleChange ( e ) {
95+ #triggerChange( value ) {
96+ if ( value < this . min || value > this . max ) {
97+ return ;
98+ }
9599 this . dispatchEvent (
96100 new CustomEvent ( 'change' , {
97101 detail : {
98- value : e . target . value ,
99- name : e . name
102+ value : value ,
103+ name : this . name ,
100104 }
101105 } )
102106 ) ;
103107 }
108+
109+ handleChange ( e ) {
110+ this . #triggerChange( e . target . value ) ;
111+ }
104112}
0 commit comments