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