Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Readonly state for uui-slider #823

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion packages/uui-slider/lib/uui-slider.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ export class UUISliderElement extends UUIFormControlMixin(LitElement, '') {
@property({ type: Boolean, reflect: true })
disabled = false;

/**
* Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
* @type {boolean}
* @attr
* @default false
*/
@property({ type: Boolean, reflect: true })
readonly = false;

/**
* Label to be used for aria-label and eventually as visual label
* @type {string}
Expand Down Expand Up @@ -296,7 +305,8 @@ export class UUISliderElement extends UUIFormControlMixin(LitElement, '') {
.value="${this.value}"
aria-label="${this.label}"
step="${+this.step}"
?disabled=${this.disabled}
?disabled=${this.disabled || this.readonly}
?readonly=${this.readonly}
@input=${this._onInput}
@change=${this._onChange} />
<div id="track" aria-hidden="true">
Expand Down Expand Up @@ -362,6 +372,7 @@ export class UUISliderElement extends UUIFormControlMixin(LitElement, '') {
.track-step {
fill: var(--uui-color-border);
}

input:hover ~ #track svg .track-step {
fill: var(--uui-color-border-emphasis);
}
Expand Down Expand Up @@ -402,6 +413,7 @@ export class UUISliderElement extends UUIFormControlMixin(LitElement, '') {
border-radius: 50%;
background-color: var(--uui-color-selected);
}

:host([disabled]) #thumb:after {
background-color: var(--uui-color-disabled);
}
Expand Down Expand Up @@ -457,6 +469,16 @@ export class UUISliderElement extends UUIFormControlMixin(LitElement, '') {
:host(:not([pristine]):invalid) #thumb:after {
background-color: var(--uui-color-danger);
}

// readonly
:host([readonly]) #thumb {
background-color: var(--uui-color-disabled);
border-color: var(--uui-color-disabled-standalone);
}

:host([readonly]) #thumb-label {
opacity: 1;
}
`,
];
}
Expand Down
7 changes: 7 additions & 0 deletions packages/uui-slider/lib/uui-slider.story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default {
hideValueLabel: false,
value: 0,
disabled: false,
readonly: false,
},
argTypes: {
label: {
Expand All @@ -38,6 +39,7 @@ const Template: Story = props => html`
min=${props.min}
max=${props.max}
?disabled=${props.disabled}
?readonly=${props.readonly}
.value=${props.value}
.hideStepValues=${props.hideStepValues}
.hideValueLabel=${props.hideValueLabel}></uui-slider>
Expand Down Expand Up @@ -72,3 +74,8 @@ export const Disabled = Template.bind({});
Disabled.args = {
disabled: true,
};

export const Readonly = Template.bind({});
Readonly.args = {
readonly: true,
};
Loading