Skip to content

Commit 9379cc1

Browse files
madsrasmusseniOvergaard
authored andcommitted
feat: implement readonly state for uui-slider
1 parent 6cbeca0 commit 9379cc1

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ export class UUISliderElement extends UUIFormControlMixin(LitElement, '') {
157157
@property({ type: Boolean, reflect: true })
158158
disabled = false;
159159

160+
/**
161+
* Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
162+
* @type {boolean}
163+
* @attr
164+
* @default false
165+
*/
166+
@property({ type: Boolean, reflect: true })
167+
readonly = false;
168+
160169
/**
161170
* Label to be used for aria-label and eventually as visual label
162171
* @type {string}
@@ -296,7 +305,8 @@ export class UUISliderElement extends UUIFormControlMixin(LitElement, '') {
296305
.value="${this.value}"
297306
aria-label="${this.label}"
298307
step="${+this.step}"
299-
?disabled=${this.disabled}
308+
?disabled=${this.disabled || this.readonly}
309+
?readonly=${this.readonly}
300310
@input=${this._onInput}
301311
@change=${this._onChange} />
302312
<div id="track" aria-hidden="true">
@@ -362,6 +372,7 @@ export class UUISliderElement extends UUIFormControlMixin(LitElement, '') {
362372
.track-step {
363373
fill: var(--uui-color-border);
364374
}
375+
365376
input:hover ~ #track svg .track-step {
366377
fill: var(--uui-color-border-emphasis);
367378
}
@@ -402,6 +413,7 @@ export class UUISliderElement extends UUIFormControlMixin(LitElement, '') {
402413
border-radius: 50%;
403414
background-color: var(--uui-color-selected);
404415
}
416+
405417
:host([disabled]) #thumb:after {
406418
background-color: var(--uui-color-disabled);
407419
}
@@ -457,6 +469,16 @@ export class UUISliderElement extends UUIFormControlMixin(LitElement, '') {
457469
:host(:not([pristine]):invalid) #thumb:after {
458470
background-color: var(--uui-color-danger);
459471
}
472+
473+
// readonly
474+
:host([readonly]) #thumb {
475+
background-color: var(--uui-color-disabled);
476+
border-color: var(--uui-color-disabled-standalone);
477+
}
478+
479+
:host([readonly]) #thumb-label {
480+
opacity: 1;
481+
}
460482
`,
461483
];
462484
}

0 commit comments

Comments
 (0)