Skip to content

Commit

Permalink
fix(next/antd): fix label overflow invalid in FormGrid (#2910)
Browse files Browse the repository at this point in the history
  • Loading branch information
ifblooms authored Mar 7, 2022
1 parent 398fac9 commit 485702c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
19 changes: 11 additions & 8 deletions packages/antd/src/form-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,18 @@ function useOverflow<
const labelCol = JSON.stringify(layout.labelCol)

useEffect(() => {
if (containerRef.current && contentRef.current) {
const contentWidth = contentRef.current.getBoundingClientRect().width
const containerWidth = containerRef.current.getBoundingClientRect().width
if (contentWidth && containerWidth && containerWidth < contentWidth) {
if (!overflow) setOverflow(true)
} else {
if (overflow) setOverflow(false)
requestAnimationFrame(() => {
if (containerRef.current && contentRef.current) {
const contentWidth = contentRef.current.getBoundingClientRect().width
const containerWidth =
containerRef.current.getBoundingClientRect().width
if (contentWidth && containerWidth && containerWidth < contentWidth) {
if (!overflow) setOverflow(true)
} else {
if (overflow) setOverflow(false)
}
}
}
})
}, [labelCol])

return {
Expand Down
19 changes: 11 additions & 8 deletions packages/next/src/form-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,18 @@ function useOverflow<
const labelCol = JSON.stringify(layout.labelCol)

useEffect(() => {
if (containerRef.current && contentRef.current) {
const contentWidth = contentRef.current.getBoundingClientRect().width
const containerWidth = containerRef.current.getBoundingClientRect().width
if (contentWidth && containerWidth && containerWidth < contentWidth) {
if (!overflow) setOverflow(true)
} else {
if (overflow) setOverflow(false)
requestAnimationFrame(() => {
if (containerRef.current && contentRef.current) {
const contentWidth = contentRef.current.getBoundingClientRect().width
const containerWidth =
containerRef.current.getBoundingClientRect().width
if (contentWidth && containerWidth && containerWidth < contentWidth) {
if (!overflow) setOverflow(true)
} else {
if (overflow) setOverflow(false)
}
}
}
})
}, [labelCol])

return {
Expand Down

0 comments on commit 485702c

Please sign in to comment.