|
38 | 38 | // state management |
39 | 39 | let focus = false; |
40 | 40 | let handleActivated = false; |
| 41 | + let handlePressed = false; |
41 | 42 | let keyboardActive = false; |
42 | 43 | let activeHandle = values.length - 1; |
43 | 44 |
|
|
273 | 274 | **/ |
274 | 275 | function moveHandle(index, value) { |
275 | 276 | if (range) { |
276 | | - // restrict the handles of a range-slider from |
| 277 | + // restrict the handles of a range-slider from |
277 | 278 | // going past one-another unless "pushy" is true |
278 | 279 | if (index === 0 && value > values[1]) { |
279 | 280 | if (pushy) { |
280 | 281 | values[1] = value; |
281 | 282 | } else { |
282 | | - value = values[1]; |
| 283 | + value = values[1]; |
283 | 284 | } |
284 | 285 | } else if (index === 1 && value < values[0]) { |
285 | 286 | if (pushy) { |
286 | 287 | values[0] = value; |
287 | 288 | } else { |
288 | | - value = values[0]; |
289 | | - } |
| 289 | + value = values[0]; |
| 290 | + } |
290 | 291 | } |
291 | 292 | } |
292 | 293 | // set the value for the handle, and align/clamp it |
|
330 | 331 | if (keyboardActive) { |
331 | 332 | focus = false; |
332 | 333 | handleActivated = false; |
| 334 | + handlePressed = false; |
333 | 335 | } |
334 | 336 | } |
335 | 337 |
|
|
393 | 395 | // set the closest handle as active |
394 | 396 | focus = true; |
395 | 397 | handleActivated = true; |
| 398 | + handlePressed = true; |
396 | 399 | activeHandle = getClosestHandle(p); |
397 | 400 | // for touch devices we want the handle to instantly |
398 | 401 | // move to the position touched for more responsive feeling |
|
401 | 404 | } |
402 | 405 | } |
403 | 406 |
|
| 407 | + /** |
| 408 | + * function to run when the user stops touching |
| 409 | + * down on the slider element anywhere |
| 410 | + * @param {event} e the event from browser |
| 411 | + **/ |
| 412 | + function sliderInteractEnd(e) { |
| 413 | + handlePressed = false; |
| 414 | + } |
| 415 | +
|
404 | 416 | /** |
405 | 417 | * unfocus the slider if the user clicked off of |
406 | 418 | * it, somewhere else on the screen |
|
442 | 454 | } |
443 | 455 | } |
444 | 456 | handleActivated = false; |
| 457 | + handlePressed = false; |
445 | 458 | } |
446 | 459 |
|
447 | 460 | /** |
|
451 | 464 | **/ |
452 | 465 | function bodyTouchEnd(e) { |
453 | 466 | handleActivated = false; |
| 467 | + handlePressed = false; |
454 | 468 | } |
455 | 469 |
|
456 | 470 | function bodyKeyDown(e) { |
|
466 | 480 | --handle-inactive: var(--range-handle-inactive, #99a2a2); |
467 | 481 | --handle: var(--range-handle, #838de7); |
468 | 482 | --handle-focus: var(--range-handle-focus, #4a40d4); |
| 483 | + --handle-border: var(--range-handle-border, var(--handle)); |
469 | 484 | --range-inactive: var(--range-range-inactive, var(--handle-inactive)); |
470 | 485 | --range: var(--range-range, var(--handle-focus)); |
471 | 486 | --float-inactive: var(--range-float-inactive, var(--handle-inactive)); |
|
511 | 526 | transform: translateY(-50%) translateX(-50%); |
512 | 527 | z-index: 2; |
513 | 528 | } |
514 | | - :global(.rangeSlider .rangeNub) { |
| 529 | + :global(.rangeSlider .rangeNub), |
| 530 | + :global(.rangeSlider .rangeHandle:before) { |
515 | 531 | position: absolute; |
516 | 532 | left: 0; |
517 | 533 | top: 0; |
|
521 | 537 | width: 100%; |
522 | 538 | transition: all 0.2s ease; |
523 | 539 | } |
| 540 | + :global(.rangeSlider .rangeHandle:before) { |
| 541 | + content: ""; |
| 542 | + left: 1px; |
| 543 | + top: 1px; |
| 544 | + bottom: 1px; |
| 545 | + right: 1px; |
| 546 | + height: auto; |
| 547 | + width: auto; |
| 548 | + box-shadow: 0 0 0 0px var(--handle-border); |
| 549 | + opacity: 0; |
| 550 | + } |
| 551 | + :global(.rangeSlider .rangeHandle.hoverable:hover:before) { |
| 552 | + box-shadow: 0 0 0 8px var(--handle-border); |
| 553 | + opacity: 0.2; |
| 554 | + } |
| 555 | + :global(.rangeSlider .rangeHandle.hoverable.press:before), |
| 556 | + :global(.rangeSlider .rangeHandle.hoverable.press:hover:before) { |
| 557 | + box-shadow: 0 0 0 12px var(--handle-border); |
| 558 | + opacity: 0.4; |
| 559 | + } |
524 | 560 | :global(.rangeSlider.range:not(.min):not(.max) .rangeNub) { |
525 | 561 | border-radius: 10em 10em 10em 1.6em; |
526 | 562 | } |
|
620 | 656 | class:pips |
621 | 657 | class:pip-labels={all === 'label' || first === 'label' || last === 'label' || rest === 'label'} |
622 | 658 | on:touchstart|preventDefault={sliderInteractStart} |
623 | | - on:mousedown={sliderInteractStart}> |
| 659 | + on:mousedown={sliderInteractStart} |
| 660 | + on:touchend|preventDefault={sliderInteractEnd} |
| 661 | + on:mouseup={sliderInteractEnd}> |
624 | 662 | {#each values as value, index} |
625 | 663 | <span |
626 | 664 | role="slider" |
627 | 665 | tabindex="0" |
628 | 666 | class="rangeHandle" |
629 | 667 | class:hoverable={hover} |
630 | 668 | class:active={focus && activeHandle === index} |
| 669 | + class:press={handlePressed && activeHandle === index} |
631 | 670 | on:blur={sliderBlurHandle} |
632 | 671 | on:focus={sliderFocusHandle} |
633 | 672 | on:keydown={sliderKeydown} |
|
0 commit comments