| 130 | // oxlint-disable react/react-compiler, react-hooks/exhaustive-deps |
| 131 | let checkForOverflow = useCallback(() => { |
| 132 | let computeHasOverflow = () => { |
| 133 | if (domRef.current && orientation === 'horizontal') { |
| 134 | let buttonGroupChildren = Array.from(domRef.current.children) as HTMLElement[]; |
| 135 | let maxX = domRef.current.offsetWidth + 1; // + 1 to account for rounding errors |
| 136 | // If any buttons have negative X positions (align="end") or extend beyond |
| 137 | // the width of the button group (align="start"), then switch to vertical. |
| 138 | if ( |
| 139 | buttonGroupChildren.some( |
| 140 | child => child.offsetLeft < 0 || child.offsetLeft + child.offsetWidth > maxX |
| 141 | ) |
| 142 | ) { |
| 143 | return true; |
| 144 | } |
| 145 | return false; |
| 146 | } |
| 147 | }; |
| 148 | if (orientation === 'horizontal') { |
| 149 | setHasOverflow(function* () { |
| 150 | // Force to horizontal for measurement. |