Skip to content

Commit

Permalink
fix(components/button): revert loading layout shift fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aminejvm committed Nov 9, 2023
1 parent 7015293 commit 69f8b0e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-ligers-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@groupos/ui-components': patch
---

Revert loading layout fix
12 changes: 1 addition & 11 deletions packages/components/src/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,15 @@ export const Button = React.forwardRef<
children: React.ReactNode
loading?: boolean
}
>(({ children, className, variant = 'primary', size = 'md', fullWidth = false, loading, style, ...props }, ref) => {
>(({ children, className, variant = 'primary', size = 'md', fullWidth = false, loading, ...props }, ref) => {
const buttonRef = React.useRef<HTMLButtonElement>(null)

React.useImperativeHandle(ref, () => buttonRef.current as HTMLButtonElement)

// prevent button from shrinking when loading
const [width, setWidth] = React.useState<number | undefined>()
React.useLayoutEffect(() => {
if (loading) return
if (buttonRef.current) {
setWidth(buttonRef.current.offsetWidth)
}
}, [variant, size, fullWidth, loading])

return (
<button
ref={buttonRef}
className={cn(buttonVariants({ variant, size, fullWidth }), loading && 'ui-cursor-wait', className)}
style={{ ...style, width: loading ? width : undefined }}
{...props}
>
{loading ? (
Expand Down

0 comments on commit 69f8b0e

Please sign in to comment.