Skip to content

Commit a9e795e

Browse files
committed
feat: prevent cumulative layout shift
1 parent 1e86658 commit a9e795e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/lib.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const Turnstile = forwardRef<TurnstileInstance | undefined, TurnstileProp
1212
onError,
1313
id,
1414
autoResetOnExpire = true,
15+
style,
1516
...divProps
1617
} = props
1718
const config = options ?? {}
@@ -99,6 +100,9 @@ export const Turnstile = forwardRef<TurnstileInstance | undefined, TurnstileProp
99100
'retry-interval': config.retryInterval ?? 8000
100101
}
101102

103+
const containerWidth = config.size === 'compact' ? '130px' : '300px'
104+
const containerHeight = config.size === 'compact' ? '120px' : '65px'
105+
102106
const onLoadScript = () => {
103107
setScriptLoaded(true)
104108
}
@@ -151,7 +155,14 @@ export const Turnstile = forwardRef<TurnstileInstance | undefined, TurnstileProp
151155
[configJson, siteKey]
152156
)
153157

154-
return <div ref={containerRef} id={containerId} {...divProps} />
158+
return (
159+
<div
160+
ref={containerRef}
161+
id={containerId}
162+
style={{ width: containerWidth, height: containerHeight, ...style }}
163+
{...divProps}
164+
/>
165+
)
155166
})
156167

157168
Turnstile.displayName = 'Turnstile'

0 commit comments

Comments
 (0)