forked from DebaucheryLibrarian/traxxx
				
			Allowing input on range track.
This commit is contained in:
		
							parent
							
								
									780993eb63
								
							
						
					
					
						commit
						370f0e784c
					
				|  | @ -12,6 +12,7 @@ | |||
| 			class="range" | ||||
| 			:class="{ disabled }" | ||||
| 			:style="{ background: `linear-gradient(90deg, var(--slider-track) ${minPercentage}%, var(--slider-range) ${minPercentage}%, var(--slider-range) ${maxPercentage}%, var(--slider-track) ${maxPercentage}%)` }" | ||||
| 			@click="setNearest" | ||||
| 		> | ||||
| 			<input | ||||
| 				v-model="valueA" | ||||
|  | @ -72,6 +73,15 @@ function emit() { | |||
| 	this.$emit('change', [this.minValue, this.maxValue]); | ||||
| } | ||||
| 
 | ||||
| function setNearest(event) { | ||||
| 	if (!this.disabled) { | ||||
| 		const closestValue = Math.round((event.offsetX / event.target.getBoundingClientRect().width) * this.max); | ||||
| 		const closestSlider = Math.abs(this.valueA - closestValue) < Math.abs(this.valueB - closestValue) ? 'valueA' : 'valueB'; | ||||
| 
 | ||||
| 		this[closestSlider] = closestValue; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| function setValue(prop, value) { | ||||
| 	if (!this.disabled) { | ||||
| 		this[prop] = value; | ||||
|  | @ -124,6 +134,7 @@ export default { | |||
| 	}, | ||||
| 	methods: { | ||||
| 		emit, | ||||
| 		setNearest, | ||||
| 		setValue, | ||||
| 	}, | ||||
| }; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue