44 * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
55 */
66import { html , LitElement } from 'lit' ;
7+ import { styleMap } from 'lit/directives/style-map.js' ;
78import { defineCustomElement } from '@vaadin/component-base/src/define.js' ;
89import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js' ;
910import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js' ;
@@ -42,7 +43,7 @@ class RangeSlider extends SliderMixin(ElementMixin(ThemableMixin(PolylitMixin(Lu
4243 */
4344 value : {
4445 type : Array ,
45- value : ( ) => [ ] ,
46+ value : ( ) => [ 0 , 100 ] ,
4647 notify : true ,
4748 sync : true ,
4849 } ,
@@ -51,14 +52,43 @@ class RangeSlider extends SliderMixin(ElementMixin(ThemableMixin(PolylitMixin(Lu
5152
5253 /** @protected */
5354 render ( ) {
55+ const [ startValue , endValue ] = this . __value ;
56+
57+ const startPercent = this . __getPercentFromValue ( startValue ) ;
58+ const endPercent = this . __getPercentFromValue ( endValue ) ;
59+
5460 return html `
5561 < div part ="track ">
56- < div part ="track-fill "> </ div >
62+ < div
63+ part ="track-fill "
64+ style ="${ styleMap ( {
65+ insetInlineStart : `${ startPercent } %` ,
66+ insetInlineEnd : `${ 100 - endPercent } %` ,
67+ } ) } "
68+ > </ div >
5769 </ div >
58- < div part ="thumb thumb-start "> </ div >
59- < div part ="thumb thumb-end "> </ div >
70+ < div part ="thumb thumb-start " style =" ${ styleMap ( { insetInlineStart : ` ${ startPercent } %` } ) } " > </ div >
71+ < div part ="thumb thumb-end " style =" ${ styleMap ( { insetInlineStart : ` ${ endPercent } %` } ) } " > </ div >
6072 ` ;
6173 }
74+
75+ constructor ( ) {
76+ super ( ) ;
77+
78+ this . __value = [ ...this . value ] ;
79+ }
80+
81+ /** @protected */
82+ updated ( props ) {
83+ super . updated ( props ) ;
84+
85+ if ( props . has ( 'value' ) || props . has ( 'min' ) || props . has ( 'max' ) ) {
86+ const value = Array . isArray ( this . value ) ? this . value : [ ] ;
87+ value . forEach ( ( value , idx ) => {
88+ this . __updateValue ( value , idx ) ;
89+ } ) ;
90+ }
91+ }
6292}
6393
6494defineCustomElement ( RangeSlider ) ;
0 commit comments