mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
fix(html): thumb edge alignment jump (#766)
This commit is contained in:
@@ -36,6 +36,8 @@ export interface SliderOptions {
|
||||
onValueCommit?: ((percent: number) => void) | undefined;
|
||||
onDragStart?: (() => void) | undefined;
|
||||
onDragEnd?: (() => void) | undefined;
|
||||
/** Called when the root element resizes (e.g. gains layout inside a popover). */
|
||||
onResize?: (() => void) | undefined;
|
||||
}
|
||||
|
||||
export interface SliderRootProps {
|
||||
@@ -310,6 +312,13 @@ export function createSlider(options: SliderOptions): SliderApi {
|
||||
};
|
||||
}
|
||||
|
||||
let resizeObserver: ResizeObserver | null = null;
|
||||
|
||||
if (options.onResize) {
|
||||
resizeObserver = new ResizeObserver(() => options.onResize!());
|
||||
resizeObserver.observe(options.getElement());
|
||||
}
|
||||
|
||||
const rootStyle: SliderRootStyle = { touchAction: 'none', userSelect: 'none' };
|
||||
|
||||
return {
|
||||
@@ -321,6 +330,7 @@ export function createSlider(options: SliderOptions): SliderApi {
|
||||
destroy() {
|
||||
if (abort.signal.aborted) return;
|
||||
abort.abort();
|
||||
resizeObserver?.disconnect();
|
||||
releaseCapture();
|
||||
cleanup();
|
||||
},
|
||||
|
||||
@@ -75,6 +75,7 @@ export class SliderElement extends MediaElement {
|
||||
this.dispatchEvent(new CustomEvent('drag-end', { bubbles: true }));
|
||||
},
|
||||
adjustPercent: (raw, thumbSize, trackSize) => this.#core.adjustPercentForAlignment(raw, thumbSize, trackSize),
|
||||
onResize: () => this.requestUpdate(),
|
||||
});
|
||||
|
||||
applyElementProps(this, this.#slider.rootProps, { signal });
|
||||
|
||||
@@ -80,6 +80,7 @@ export class TimeSliderElement extends MediaElement {
|
||||
this.dispatchEvent(new CustomEvent('drag-end', { bubbles: true }));
|
||||
},
|
||||
adjustPercent: (raw, thumbSize, trackSize) => this.#core.adjustPercentForAlignment(raw, thumbSize, trackSize),
|
||||
onResize: () => this.requestUpdate(),
|
||||
});
|
||||
|
||||
applyElementProps(this, this.#slider.rootProps, { signal });
|
||||
|
||||
@@ -76,6 +76,7 @@ export class VolumeSliderElement extends MediaElement {
|
||||
this.dispatchEvent(new CustomEvent('drag-end', { bubbles: true }));
|
||||
},
|
||||
adjustPercent: (raw, thumbSize, trackSize) => this.#core.adjustPercentForAlignment(raw, thumbSize, trackSize),
|
||||
onResize: () => this.requestUpdate(),
|
||||
});
|
||||
|
||||
applyElementProps(this, this.#slider.rootProps, { signal });
|
||||
|
||||
Reference in New Issue
Block a user