From b06d91c8e4be33dba6a2c787c6bfaede7cc9c9f1 Mon Sep 17 00:00:00 2001 From: ZIA-Hans <1025013204@qq.com> Date: Fri, 1 Mar 2024 11:45:44 +0800 Subject: [PATCH 1/4] fix(countdown): fix the separator re-render error when the separator appears fix #47 --- packages/banana/src/countdown/index.ts | 33 +++++++++++++++----------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/banana/src/countdown/index.ts b/packages/banana/src/countdown/index.ts index 89f9d2a5..01efafdc 100644 --- a/packages/banana/src/countdown/index.ts +++ b/packages/banana/src/countdown/index.ts @@ -45,28 +45,33 @@ export default class BCountdown extends LitElement { @queryAll('[part="separator"]') private _aliveSeparator: HTMLElement[] | undefined; - private replaceSeparator() { + private _replaceSeparator() { // Don't deal replace separator operation when separator isn't changed if (this._prevSeparator?.textContent === this._separator?.[0]?.textContent) return; // Remove and record old separator when separator alive - if (this.separate && this._separator && this._separator.length > 0) { + + if (this.separate) { if (this._aliveSeparator?.length) { this._prevSeparator = this._aliveSeparator[0]; for (const separatorItem of this._aliveSeparator) { this._countdownSeparate?.removeChild(separatorItem); } } - const separatorContent = this._separator; - // Set part attribute for separator - separatorContent[0].setAttribute('part', 'separator'); - const countdownItems = this._countdownSeparate?.querySelectorAll('.countdown__item'); - countdownItems?.forEach((item, index) => { - if (index === 0) { - return; - } - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - item.insertAdjacentElement('beforebegin', separatorContent[0].cloneNode(true) as HTMLElement); - }); + + // Adapt to the scene where the separator appears or not + if (this._separator && this._separator.length > 0) { + const separatorContent = this._separator; + // Set part attribute for separator + separatorContent[0].setAttribute('part', 'separator'); + const countdownItems = this._countdownSeparate?.querySelectorAll('.countdown__item'); + countdownItems?.forEach((item, index) => { + if (index === 0) { + return; + } + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + item.insertAdjacentElement('beforebegin', separatorContent[0].cloneNode(true) as HTMLElement); + }); + } } } @@ -109,7 +114,7 @@ export default class BCountdown extends LitElement { render() { // If separate is true, insert separator between countdown items - this.replaceSeparator(); + this._replaceSeparator(); const _timeDataObject = formatTimeStr(this._timeLeft, this.format); const _time = _timeDataObject.text; From bdf40c9f128e07c7496b212b97d96bc9363703c4 Mon Sep 17 00:00:00 2001 From: ZIA-Hans <1025013204@qq.com> Date: Fri, 1 Mar 2024 11:46:30 +0800 Subject: [PATCH 2/4] chore: new version --- .changeset/fluffy-crabs-tickle.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/fluffy-crabs-tickle.md diff --git a/.changeset/fluffy-crabs-tickle.md b/.changeset/fluffy-crabs-tickle.md new file mode 100644 index 00000000..b088f629 --- /dev/null +++ b/.changeset/fluffy-crabs-tickle.md @@ -0,0 +1,6 @@ +--- +'@banana-ui/banana': patch +'@banana-ui/react': patch +--- + +fix the separator re-render error when the separator appears From b7a75c36efda7edde252689c287f7c18c65aaaf0 Mon Sep 17 00:00:00 2001 From: ZIA-Hans <1025013204@qq.com> Date: Fri, 1 Mar 2024 15:03:36 +0800 Subject: [PATCH 3/4] fix(countdown): fix question of separate render abnormal when the separate visiable status changed fix #47 --- packages/banana/src/countdown/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/banana/src/countdown/index.ts b/packages/banana/src/countdown/index.ts index 01efafdc..0a36c0fc 100644 --- a/packages/banana/src/countdown/index.ts +++ b/packages/banana/src/countdown/index.ts @@ -49,7 +49,6 @@ export default class BCountdown extends LitElement { // Don't deal replace separator operation when separator isn't changed if (this._prevSeparator?.textContent === this._separator?.[0]?.textContent) return; // Remove and record old separator when separator alive - if (this.separate) { if (this._aliveSeparator?.length) { this._prevSeparator = this._aliveSeparator[0]; @@ -71,6 +70,8 @@ export default class BCountdown extends LitElement { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion item.insertAdjacentElement('beforebegin', separatorContent[0].cloneNode(true) as HTMLElement); }); + } else { + this._prevSeparator = undefined; } } } From 20d28eab29a6238ec04b86fc8aeaddf718e6dbfb Mon Sep 17 00:00:00 2001 From: ZIA-Hans <1025013204@qq.com> Date: Fri, 1 Mar 2024 15:07:19 +0800 Subject: [PATCH 4/4] chore: new version --- .changeset/strong-dogs-attend.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/strong-dogs-attend.md diff --git a/.changeset/strong-dogs-attend.md b/.changeset/strong-dogs-attend.md new file mode 100644 index 00000000..a3ee7566 --- /dev/null +++ b/.changeset/strong-dogs-attend.md @@ -0,0 +1,6 @@ +--- +'@banana-ui/banana': patch +'@banana-ui/react': patch +--- + +fix question of separate render abnormal when the separate visiable status changed