Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(components): [Component] [table] Table 在一定条件下宽度会无限延长 #13052 #16391

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions packages/components/table/src/table/style-helper.ts
Expand Up @@ -108,6 +108,23 @@ function useStyle<T>(
}
})

const elPaddingMarginHorizontal = (el: HTMLElement) => {
return (
(el.style.paddingLeft === ''
? 0
: Number.parseFloat(el.style.paddingLeft)) +
(el.style.marginLeft === ''
? 0
: Number.parseFloat(el.style.marginLeft)) +
(el.style.marginRight === ''
? 0
: Number.parseFloat(el.style.marginRight)) +
(el.style.paddingRight === ''
? 0
: Number.parseFloat(el.style.paddingRight))
)
}

const doLayout = () => {
if (shouldUpdateHeight.value) {
layout.updateElsHeight()
Expand All @@ -130,12 +147,13 @@ function useStyle<T>(
}

resizeState.value = {
width: (tableWidth.value = el.offsetWidth),
width: el.offsetWidth,
height: el.offsetHeight,
headerHeight:
props.showHeader && tableHeader ? tableHeader.offsetHeight : null,
}

tableWidth.value = el.offsetWidth - elPaddingMarginHorizontal(el)
// init filters
store.states.columns.value.forEach((column: TableColumnCtx<T>) => {
if (column.filteredValue && column.filteredValue.length) {
Expand Down Expand Up @@ -223,7 +241,8 @@ function useStyle<T>(
headerHeight: oldHeaderHeight,
} = resizeState.value

const width = (tableWidth.value = el.offsetWidth)
tableWidth.value = el.offsetWidth - elPaddingMarginHorizontal(el)
const width = tableWidth.value
if (oldWidth !== width) {
shouldUpdateLayout = true
}
Expand Down