Skip to content

Commit 9fc1291

Browse files
committed
fix: button busy spinners retain original width
1 parent 00cb457 commit 9fc1291

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

lib/button.css.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,18 @@ export const iconClassName = style({
121121
width: '0.7em', // hack, this should be variable based on the font-size
122122
});
123123

124-
export const visiblyHiddenClass = style({
125-
visibility: 'hidden',
126-
});
127-
128124
export const busyButtonClass = style({
129125
pointerEvents: 'none',
130126
});
131127

128+
export const busySpinnerClass = style({
129+
position: 'absolute',
130+
});
131+
132132
export const inlineBleedClass = style({
133133
marginBlock: calc(propsVars.space[0]).negate().toString(),
134134
});
135+
136+
export const visiblyHiddenClass = style({
137+
visibility: 'hidden',
138+
});

lib/button.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
iconClassName,
1616
inlineBleedClass,
1717
visiblyHiddenClass,
18+
busySpinnerClass,
1819
} from './button.css.js';
1920
import { differentOriginLinkProps } from './component-utils.js';
2021
import { useStringLikeDetector } from './hooks/use-string-like.js';
@@ -68,17 +69,11 @@ export type ButtonIconProps<
6869
}
6970
>;
7071

71-
/** @private */
72-
const IconBox: FC<{
72+
const IconBox: FC<BoxProps<'span'> & {
7373
icon: ReactElement | FC;
74-
busy?: boolean | Falsy;
7574
capSize?: FontSize;
76-
}> = ({ icon, busy, ...props }) => (
77-
<Box
78-
{...props}
79-
component="span"
80-
className={[iconClassName, busy && visiblyHiddenClass]}
81-
>
75+
}> = ({ icon, className, ...props }) => (
76+
<Box {...props} component="span" className={[className, iconClassName]}>
8277
{isValidElement<ReactElementDefaultPropsType>(icon)
8378
? icon
8479
: icon({} /* { className: iconClassName } */)}
@@ -199,10 +194,10 @@ export const Button = forwardRef(
199194
]}
200195
>
201196
{iconStart && (
202-
<IconBox capSize={fontSize} busy={busy} icon={iconStart} />
197+
<IconBox capSize={fontSize} icon={iconStart} {...busyAttributes} />
203198
)}
204199

205-
{!busy && hasStringChildren && (
200+
{hasStringChildren && (
206201
<ExactText
207202
component="span"
208203
textAlign={textAlign}
@@ -213,15 +208,17 @@ export const Button = forwardRef(
213208
</ExactText>
214209
)}
215210

216-
{!busy && children && !hasStringChildren && (
211+
{!hasStringChildren && children && (
217212
<Box flexGrow component="span" {...busyAttributes}>
218213
{children}
219214
</Box>
220215
)}
221216

222-
{busy && <Spinner capSize={fontSize} />}
217+
{busy && <Spinner className={busySpinnerClass} capSize={fontSize} />}
223218

224-
{iconEnd && <IconBox capSize={fontSize} busy={busy} icon={iconEnd} />}
219+
{iconEnd && (
220+
<IconBox capSize={fontSize} icon={iconEnd} {...busyAttributes} />
221+
)}
225222
</UnstyledButton>
226223
);
227224
},

0 commit comments

Comments
 (0)