From 4c751207b38ed3c8b347ad634ab90c4d18cfde83 Mon Sep 17 00:00:00 2001 From: yuexing Date: Thu, 24 Aug 2023 18:36:59 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix(cascader):=20=F0=9F=90=9E=20default=20n?= =?UTF-8?q?o=20go=20top?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix cascading default not returning to top --- src/OptionList/index.tsx | 2 +- src/utils/commonUtil.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/OptionList/index.tsx b/src/OptionList/index.tsx index 45d8a9d7..b55ee783 100644 --- a/src/OptionList/index.tsx +++ b/src/OptionList/index.tsx @@ -164,7 +164,7 @@ const RefOptionList = React.forwardRef((props, ref) => { `li[data-path-key="${cellKeyPath.replace(/\\{0,2}"/g, '\\"')}"]`, // matches unescaped double quotes ); if (ele) { - scrollIntoParentView(ele); + scrollIntoParentView(ele, activeValueCells); } } }, [activeValueCells]); diff --git a/src/utils/commonUtil.ts b/src/utils/commonUtil.ts index 8a355425..142abd22 100644 --- a/src/utils/commonUtil.ts +++ b/src/utils/commonUtil.ts @@ -43,7 +43,7 @@ export function isLeaf(option: DefaultOptionType, fieldNames: FieldNames) { return option.isLeaf ?? !option[fieldNames.children]?.length; } -export function scrollIntoParentView(element: HTMLElement) { +export function scrollIntoParentView(element: HTMLElement, activeValueCells: React.Key[]) { const parent = element.parentElement; if (!parent) { return; @@ -54,6 +54,12 @@ export function scrollIntoParentView(element: HTMLElement) { parent.scrollTo({ top: elementToParent }); } else if (elementToParent + element.offsetHeight - parent.scrollTop > parent.offsetHeight) { parent.scrollTo({ top: elementToParent + element.offsetHeight - parent.offsetHeight }); + } else { + const parentToContainer = parent.parentElement.children; + if(activeValueCells.length === parentToContainer.length) return + if(typeof parentToContainer[activeValueCells.length] !== undefined){ + parentToContainer[activeValueCells.length].scrollTo(0, 0) + } } } From 18fe05dcdea0f518ecb2179c4313eb4a59f0baef Mon Sep 17 00:00:00 2001 From: yuexing Date: Thu, 24 Aug 2023 19:00:08 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=90=9E=20fix(cascader):=20fix=20test?= =?UTF-8?q?=20Use=20Cases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/commonUtil.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/utils/commonUtil.ts b/src/utils/commonUtil.ts index 142abd22..2cd6e65a 100644 --- a/src/utils/commonUtil.ts +++ b/src/utils/commonUtil.ts @@ -57,9 +57,13 @@ export function scrollIntoParentView(element: HTMLElement, activeValueCells: Rea } else { const parentToContainer = parent.parentElement.children; if(activeValueCells.length === parentToContainer.length) return - if(typeof parentToContainer[activeValueCells.length] !== undefined){ - parentToContainer[activeValueCells.length].scrollTo(0, 0) + const container = parentToContainer[activeValueCells.length]; + if (container && typeof container.scrollTo === 'function') { + container.scrollTo(0, 0); + } else { + console.error("container || scrollTo error"); } + } } From 0fb084f3fcd9c495271eab3f839880ef749e15fe Mon Sep 17 00:00:00 2001 From: yuexing Date: Thu, 24 Aug 2023 19:09:00 +0800 Subject: [PATCH 3/5] fix(cascader): del console --- src/utils/commonUtil.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/utils/commonUtil.ts b/src/utils/commonUtil.ts index 2cd6e65a..5bd764a3 100644 --- a/src/utils/commonUtil.ts +++ b/src/utils/commonUtil.ts @@ -60,10 +60,7 @@ export function scrollIntoParentView(element: HTMLElement, activeValueCells: Rea const container = parentToContainer[activeValueCells.length]; if (container && typeof container.scrollTo === 'function') { container.scrollTo(0, 0); - } else { - console.error("container || scrollTo error"); - } - + } } } From baa61ac1aa34fcbbb9a70f8abd6209394f3eb080 Mon Sep 17 00:00:00 2001 From: yuexing Date: Fri, 25 Aug 2023 09:40:51 +0800 Subject: [PATCH 4/5] fix: test vercel --- src/OptionList/index.tsx | 2 +- src/utils/commonUtil.ts | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/OptionList/index.tsx b/src/OptionList/index.tsx index b55ee783..45d8a9d7 100644 --- a/src/OptionList/index.tsx +++ b/src/OptionList/index.tsx @@ -164,7 +164,7 @@ const RefOptionList = React.forwardRef((props, ref) => { `li[data-path-key="${cellKeyPath.replace(/\\{0,2}"/g, '\\"')}"]`, // matches unescaped double quotes ); if (ele) { - scrollIntoParentView(ele, activeValueCells); + scrollIntoParentView(ele); } } }, [activeValueCells]); diff --git a/src/utils/commonUtil.ts b/src/utils/commonUtil.ts index 5bd764a3..8a355425 100644 --- a/src/utils/commonUtil.ts +++ b/src/utils/commonUtil.ts @@ -43,7 +43,7 @@ export function isLeaf(option: DefaultOptionType, fieldNames: FieldNames) { return option.isLeaf ?? !option[fieldNames.children]?.length; } -export function scrollIntoParentView(element: HTMLElement, activeValueCells: React.Key[]) { +export function scrollIntoParentView(element: HTMLElement) { const parent = element.parentElement; if (!parent) { return; @@ -54,13 +54,6 @@ export function scrollIntoParentView(element: HTMLElement, activeValueCells: Rea parent.scrollTo({ top: elementToParent }); } else if (elementToParent + element.offsetHeight - parent.scrollTop > parent.offsetHeight) { parent.scrollTo({ top: elementToParent + element.offsetHeight - parent.offsetHeight }); - } else { - const parentToContainer = parent.parentElement.children; - if(activeValueCells.length === parentToContainer.length) return - const container = parentToContainer[activeValueCells.length]; - if (container && typeof container.scrollTo === 'function') { - container.scrollTo(0, 0); - } } } From 095dc599e735d06e6ebc64ba5ea61ff2a31615e1 Mon Sep 17 00:00:00 2001 From: yuexing Date: Fri, 25 Aug 2023 09:44:21 +0800 Subject: [PATCH 5/5] fix: recovery code --- src/OptionList/index.tsx | 2 +- src/utils/commonUtil.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/OptionList/index.tsx b/src/OptionList/index.tsx index 45d8a9d7..b55ee783 100644 --- a/src/OptionList/index.tsx +++ b/src/OptionList/index.tsx @@ -164,7 +164,7 @@ const RefOptionList = React.forwardRef((props, ref) => { `li[data-path-key="${cellKeyPath.replace(/\\{0,2}"/g, '\\"')}"]`, // matches unescaped double quotes ); if (ele) { - scrollIntoParentView(ele); + scrollIntoParentView(ele, activeValueCells); } } }, [activeValueCells]); diff --git a/src/utils/commonUtil.ts b/src/utils/commonUtil.ts index 8a355425..bf71d374 100644 --- a/src/utils/commonUtil.ts +++ b/src/utils/commonUtil.ts @@ -43,7 +43,7 @@ export function isLeaf(option: DefaultOptionType, fieldNames: FieldNames) { return option.isLeaf ?? !option[fieldNames.children]?.length; } -export function scrollIntoParentView(element: HTMLElement) { +export function scrollIntoParentView(element: HTMLElement, activeValueCells: React.Key[]) { const parent = element.parentElement; if (!parent) { return; @@ -54,6 +54,13 @@ export function scrollIntoParentView(element: HTMLElement) { parent.scrollTo({ top: elementToParent }); } else if (elementToParent + element.offsetHeight - parent.scrollTop > parent.offsetHeight) { parent.scrollTo({ top: elementToParent + element.offsetHeight - parent.offsetHeight }); + } else { + const parentToContainer = parent.parentElement.children; + if(!activeValueCells.length || activeValueCells.length === parentToContainer.length) return + const container = parentToContainer[activeValueCells.length]; + if (container && typeof container.scrollTo === 'function') { + container.scrollTo({top: 0}); + } } }