Skip to content

Slider with gradient background styling. #521

Closed
@Westbrook

Description

@Westbrook

Description

With the current slider track DOM structure: [===Left Track===] (Knob) [===Right Track===]

<div class="spectrum-Slider-track" style="width: 40%"></div>
<div class="spectrum-Slider-handle" style="left: 40%;">
      <input type="range" class="spectrum-Slider-input" value="14" step="2" min="10" max="20">
</div>
<div class="spectrum-Slider-track" style="width: 60%"></div>

The ability to create a gradient slider, a la https://spectrum.adobe.com/page/slider/#Gradient, is pretty difficult. Particularly because both .spectrum-Slider-track elements are assigned the same --spectrum-slider-track-color custom property to manage their background. As solid color, this is fine, but for a gradient that should uniformly span the width of the slider element the hacks to work around that are dubious.

I'd like to suggest the possibility of addressing this UI by altering the clip-path of the .spectrum-Slider-track elements, rather than their width.

<div class="spectrum-Slider-track" style="
clip-path: polygon(
    calc(40% - var(
                --spectrum-slider-handle-gap,
                var(
                    --spectrum-alias-border-size-thicker
                )
            )) 0,
    100%  0,
    100% 100%,
    calc(40% - var(
                --spectrum-slider-handle-gap,
                var(
                    --spectrum-alias-border-size-thicker
                )
            )) 100%
);"></div>
<div class="spectrum-Slider-handle" style="left: 40%;">
      <input type="range" class="spectrum-Slider-input" value="14" step="2" min="10" max="20">
</div>
<div class="spectrum-Slider-track" style="
clip-path: polygon(
    calc(40% + var(
                --spectrum-slider-handle-gap,
                var(
                    --spectrum-alias-border-size-thicker
                )
            )) 0,
    100%  0,
    100% 100%,
    calc(40% - var(
                --spectrum-slider-handle-gap,
                var(
                    --spectrum-alias-border-size-thicker
                )
            )) 100%
);"></div>

It's a pretty heavy lift to have all of that clip-path rule in the inline styles, but this could be translated to a single --spectrum-slider-track-percentage property that hid all of that complexity inside of the delivered styles.

The main alteration that is needed from Spectrum CSS is to ensure .spectrum-Slider-track { width: 100%; } and then the same track color (e.g. --spectrum-slider-track-color: linear-gradient(to right, red, green 100%)) would be applicable to both tracks and allow the UI desired. Doing the same to .spectrum-Slider-fill would similarly allow the --spectrum-slider-fill-track-color custom property to support the same when the filled variant is used.

The Spectrum Web Components team has previously prototyped this in the following PR: adobe/spectrum-web-components#456
image

Why do you need this feature or component?

Cleaner support for Spectrum specification for usage in our applications.

Possible issues:

clip-path has mixed browser support in the long tail, so I'm not sure how it intersection with your browser support matrix; needs checking in Edge/IE 11 as clip-path is listed as "only supporting url()" in those browsers depending on which Can I Use you rely on: https://caniuse.com/#search=clip-path

synced to jira: https://jira.corp.adobe.com/browse/CSS-215

Metadata

Metadata

Assignees

No one assigned

    Labels

    ask designQuestions or topics for the design teamsync to jiraThese will be pushed into adobe internal jira

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions