fix(range): gesture is now properly re-created on connectedCallback (#22407)

resolves #22335
This commit is contained in:
Liam DeBeasi
2020-11-02 10:50:08 -05:00
committed by GitHub
parent 27191026ef
commit 2fea36fc98

View File

@ -28,6 +28,7 @@ import { createColorClasses, hostContext } from '../../utils/theme';
}) })
export class Range implements ComponentInterface { export class Range implements ComponentInterface {
private didLoad = false;
private noUpdate = false; private noUpdate = false;
private rect!: ClientRect; private rect!: ClientRect;
private hasFocus = false; private hasFocus = false;
@ -177,20 +178,7 @@ export class Range implements ComponentInterface {
*/ */
@Event() ionBlur!: EventEmitter<void>; @Event() ionBlur!: EventEmitter<void>;
connectedCallback() { private setupGesture = async () => {
this.updateRatio();
this.debounceChanged();
this.disabledChanged();
}
disconnectedCallback() {
if (this.gesture) {
this.gesture.destroy();
this.gesture = undefined;
}
}
async componentDidLoad() {
const rangeSlider = this.rangeSlider; const rangeSlider = this.rangeSlider;
if (rangeSlider) { if (rangeSlider) {
this.gesture = (await import('../../utils/gesture')).createGesture({ this.gesture = (await import('../../utils/gesture')).createGesture({
@ -206,6 +194,34 @@ export class Range implements ComponentInterface {
} }
} }
componentDidLoad() {
this.setupGesture();
this.didLoad = true;
}
connectedCallback() {
this.updateRatio();
this.debounceChanged();
this.disabledChanged();
/**
* If we have not yet rendered
* ion-range, then rangeSlider is not defined.
* But if we are moving ion-range via appendChild,
* then rangeSlider will be defined.
*/
if (this.didLoad) {
this.setupGesture();
}
}
disconnectedCallback() {
if (this.gesture) {
this.gesture.destroy();
this.gesture = undefined;
}
}
private handleKeyboard = (knob: KnobName, isIncrease: boolean) => { private handleKeyboard = (knob: KnobName, isIncrease: boolean) => {
let step = this.step; let step = this.step;
step = step > 0 ? step : 1; step = step > 0 ? step : 1;