Skip to content

Commit e720227

Browse files
madsrasmusseniOvergaard
authored andcommitted
feat: implement readonly for uui-range-slider
1 parent 07a4019 commit e720227

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

packages/uui-range-slider/lib/uui-range-slider.element.ts

+29-5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ export class UUIRangeSliderElement extends UUIFormControlMixin(LitElement, '') {
4646
@property({ type: Boolean, reflect: true })
4747
disabled = false;
4848

49+
/**
50+
* Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
51+
* @type {boolean}
52+
* @attr
53+
* @default false
54+
*/
55+
@property({ type: Boolean, reflect: true })
56+
readonly = false;
57+
4958
/**
5059
* Sets the minimum allowed value.
5160
* @type {number}
@@ -488,6 +497,7 @@ export class UUIRangeSliderElement extends UUIFormControlMixin(LitElement, '') {
488497
/** Mouse Event */
489498
private _onMouseDown = (e: MouseEvent) => {
490499
if (this.disabled) return;
500+
if (this.readonly) return;
491501

492502
const target = e.composedPath()[0];
493503
if (target === this._outerTrack) return;
@@ -554,6 +564,8 @@ export class UUIRangeSliderElement extends UUIFormControlMixin(LitElement, '') {
554564
/** Input Events */
555565
private _onLowInput(e: Event) {
556566
if (this.disabled) e.preventDefault();
567+
if (this.readonly) e.preventDefault();
568+
557569
this._currentFocus = this._inputLow;
558570
const newValue = Number((e.target as HTMLInputElement).value);
559571

@@ -563,6 +575,8 @@ export class UUIRangeSliderElement extends UUIFormControlMixin(LitElement, '') {
563575

564576
private _onHighInput(e: Event) {
565577
if (this.disabled) e.preventDefault();
578+
if (this.readonly) e.preventDefault();
579+
566580
this._currentFocus = this._inputHigh;
567581
const newValue = Number((e.target as HTMLInputElement).value);
568582

@@ -675,7 +689,7 @@ export class UUIRangeSliderElement extends UUIFormControlMixin(LitElement, '') {
675689
step=${this._step}
676690
.value=${this._lowInputValue.toString()}
677691
aria-label="${this.label} low-end value"
678-
?disabled="${this.disabled}"
692+
?disabled="${this.disabled || this.readonly}"
679693
@input=${this._onLowInput}
680694
@change=${this._onLowChange} />
681695
<input
@@ -687,7 +701,7 @@ export class UUIRangeSliderElement extends UUIFormControlMixin(LitElement, '') {
687701
step="${this._step}"
688702
.value=${this._highInputValue.toString()}
689703
aria-label="${this.label} high-end value"
690-
?disabled="${this.disabled}"
704+
?disabled="${this.disabled || this.readonly}"
691705
@input=${this._onHighInput}
692706
@change=${this._onHighChange} />
693707
</div>`;
@@ -744,7 +758,8 @@ export class UUIRangeSliderElement extends UUIFormControlMixin(LitElement, '') {
744758
z-index: ${Z_INDEX.CENTER};
745759
}
746760
747-
:host([disabled]) #inner-color-thumb {
761+
:host([disabled]) #inner-color-thumb,
762+
:host([readonly]) #inner-color-thumb {
748763
cursor: default;
749764
}
750765
@@ -757,10 +772,12 @@ export class UUIRangeSliderElement extends UUIFormControlMixin(LitElement, '') {
757772
#inner-color-thumb:focus .color {
758773
background-color: var(--color-focus);
759774
}
775+
760776
#inner-color-thumb:hover .color,
761777
#inner-color-thumb .color.active {
762778
background-color: var(--color-hover);
763779
}
780+
764781
#inner-color-thumb:hover .color {
765782
height: 5px;
766783
background-color: var(--color-hover);
@@ -892,6 +909,10 @@ export class UUIRangeSliderElement extends UUIFormControlMixin(LitElement, '') {
892909
color: var(--uui-palette-mine-grey);
893910
}
894911
912+
:host([readonly]) .thumb-values {
913+
opacity: 1;
914+
}
915+
895916
#range-slider:hover .thumb-values {
896917
opacity: 1;
897918
}
@@ -914,7 +935,9 @@ export class UUIRangeSliderElement extends UUIFormControlMixin(LitElement, '') {
914935
inset 0 0 0 2px var(--color-interactive),
915936
inset 0 0 0 4px var(--uui-color-surface);
916937
}
917-
:host([disabled]) input::-webkit-slider-thumb {
938+
939+
:host([disabled]) input::-webkit-slider-thumb,
940+
:host([readonly]) input::-webkit-slider-thumb {
918941
cursor: default;
919942
}
920943
@@ -958,7 +981,8 @@ export class UUIRangeSliderElement extends UUIFormControlMixin(LitElement, '') {
958981
inset 0 0 0 2px var(--color-interactive),
959982
inset 0 0 0 4px var(--uui-color-surface);
960983
}
961-
:host([disabled]) input::-moz-range-thumb {
984+
:host([disabled]) input::-moz-range-thumb,
985+
:host([readonly]) input::-moz-range-thumb {
962986
cursor: default;
963987
}
964988

0 commit comments

Comments
 (0)