From ba6bed97e8c9eaee4ad1543e800b11a8c73fe258 Mon Sep 17 00:00:00 2001 From: sunhao Date: Sat, 9 Dec 2023 14:49:39 +0800 Subject: [PATCH] * pick: refactor Pick component. --- lib/pick/src/components/pick.tsx | 35 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/pick/src/components/pick.tsx b/lib/pick/src/components/pick.tsx index 4dba9ff220..45e3677683 100644 --- a/lib/pick/src/components/pick.tsx +++ b/lib/pick/src/components/pick.tsx @@ -18,14 +18,15 @@ export class Pick = Pi popMinWidth: 50, popMinHeight: 32, popMaxHeight: 300, + clickType: 'open', }; - #id: string; + _id: string; - #toggleTimer = 0; + _toggleTimer = 0; - #pop: RefObject>> = createRef(); + _pop: RefObject>> = createRef(); protected _trigger = createRef(); @@ -36,16 +37,16 @@ export class Pick = Pi open: false, } as S; - this.#id = props.id ?? `_pick${nextGid()}`; + this._id = props.id ?? `_pick${nextGid()}`; this.changeState = this.changeState.bind(this); } get id() { - return this.#id; + return this._id; } get pop() { - return this.#pop.current; + return this._pop.current; } get value() { @@ -73,9 +74,9 @@ export class Pick = Pi return this.state; } - if (this.#toggleTimer) { - clearTimeout(this.#toggleTimer); - this.#toggleTimer = 0; + if (this._toggleTimer) { + clearTimeout(this._toggleTimer); + this._toggleTimer = 0; } let newState = await this.changeState(prevState => { @@ -90,16 +91,16 @@ export class Pick = Pi if (openState === 'closing') { await delay(200, (id) => { - this.#toggleTimer = id; + this._toggleTimer = id; }); - this.#toggleTimer = 0; + this._toggleTimer = 0; newState = await this.changeState({open: false} as Partial); } else if (openState === 'opening') { await delay(50, (id) => { - this.#toggleTimer = id; + this._toggleTimer = id; }); - this.#toggleTimer = 0; + this._toggleTimer = 0; newState = await this.changeState({open: true} as Partial); } @@ -241,10 +242,10 @@ export class Pick = Pi componentWillUnmount(): void { this.props.beforeDestroy?.call(this); - if (this.#toggleTimer) { - clearTimeout(this.#toggleTimer); + if (this._toggleTimer) { + clearTimeout(this._toggleTimer); } - const pop = this.#pop.current as unknown as Component>; + const pop = this._pop.current as unknown as Component>; if (pop && pop.componentWillUnmount) { pop.componentWillUnmount(); } @@ -256,7 +257,7 @@ export class Pick = Pi let popView: ComponentChildren; if (opened && (!props.hidePopWhenEmpty || !this._isEmptyValue())) { const Pop = this._getPop(props); - popView = ( + popView = ( {this._renderPop(props, state)} ); }