MCPcopy Create free account
hub / github.com/adobe/react-spectrum / computeHasOverflow

Function computeHasOverflow

packages/@react-spectrum/s2/src/ButtonGroup.tsx:133–148  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

ButtonGroup.tsxFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected