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

Function computeHasOverflow

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

Source from the content-addressed store, hash-verified

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.

Callers 1

ButtonGroup.tsxFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected