Skip to content

Commit

Permalink
fix(slider): ensure first render when no "value" is supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook committed Aug 29, 2023
1 parent 9e5c0f7 commit eed860b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
8 changes: 2 additions & 6 deletions packages/slider/src/HandleController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ import {
} from '@spectrum-web-components/base/src/directives.js';
import { MutationController } from '@lit-labs/observers/mutation-controller.js';
import { Slider } from './Slider.js';
import {
Controller,
SliderHandle,
SliderNormalization,
} from './SliderHandle.js';
import { SliderHandle, SliderNormalization } from './SliderHandle.js';

interface HandleReference {
handle: HTMLElement;
Expand Down Expand Up @@ -61,7 +57,7 @@ export interface HandleValueDictionary {
[key: string]: number;
}

export class HandleController implements Controller {
export class HandleController {
private host!: Slider;
private handles: Map<string, SliderHandle> = new Map();
private model: ModelValue[] = [];
Expand Down
11 changes: 3 additions & 8 deletions packages/slider/src/SliderHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
NumberFormatOptions,
NumberFormatter,
} from '@internationalized/number';
import { HandleController } from './HandleController.js';

export type HandleMin = number | 'previous';
export type HandleMax = number | 'next';
Expand All @@ -30,13 +31,6 @@ export type HandleValues = {
value: number;
}[];

export interface Controller {
inputForHandle(handle: SliderHandle): HTMLInputElement | undefined;
requestUpdate(): void;
setValueFromHandle(handle: SliderHandle): void;
handleHasChanged(handle: SliderHandle): void;
}

export type SliderNormalization = {
toNormalized: (value: number, min: number, max: number) => number;
fromNormalized: (value: number, min: number, max: number) => number;
Expand Down Expand Up @@ -78,7 +72,7 @@ const MaxConverter = {
* @fires change - An alteration to the value of the element has been committed by the user.
*/
export class SliderHandle extends Focusable {
public handleController?: Controller;
public handleController?: HandleController;

public get handleName(): string {
return this.name;
Expand Down Expand Up @@ -138,6 +132,7 @@ export class SliderHandle extends Focusable {
if (this.value == null) {
if (!isNaN(max) && !isNaN(min)) {
this.value = max < min ? min : min + (max - min) / 2;
this.handleController?.hostUpdate();
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions packages/slider/stories/slider.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ export const Default = (args: StoryArgs = {}): TemplateResult => {
`;
};

export const minimalDOM = (): TemplateResult => {
return html`
<div style="width: 500px; margin: 12px 20px;">
<sp-slider>Opacity</sp-slider>
</div>
`;
};

export const noVisibleTextLabel = (args: StoryArgs = {}): TemplateResult => {
return html`
<div style="width: 500px; margin: 12px 20px;">
Expand Down

0 comments on commit eed860b

Please sign in to comment.