Skip to content

Commit 94ea0b2

Browse files
committed
fix: remove container option, use native id prop to modify default id
1 parent 414e352 commit 94ea0b2

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
https://react-turnstile.vercel.app/
2020

2121
## Install
22-
1. First, [follow these steps](https://developers.cloudflare.com/turnstile/get-started/) to obtain a free site key and secret key from Cloudflare.
22+
1. [Follow these steps](https://developers.cloudflare.com/turnstile/get-started/) to obtain a free site key and secret key from Cloudflare.
2323
2. Install `@marsidev/react-turnstile` into your React application.
2424

2525
```bash
@@ -54,13 +54,12 @@ function Widget() {
5454

5555

5656
### Render options
57-
| **Option** | **Type** | **Default** | **Description** |
58-
| ---------- | ------------------------- | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
59-
| container | `string` or `HTMLElement` | `'cf-turnstile'` | Container ID or container node that will wrap the widget iframe. |
60-
| theme | `string` | `'auto'` | The widget theme. You can choose between `light`, `dark` or `auto`. |
61-
| tabIndex | `number` | `0` | The `tabindex` of Turnstile’s iframe for accessibility purposes. |
62-
| action | `string` | `undefined` | A customer value that can be used to differentiate widgets under the same `sitekey` in analytics and which is returned upon validation. This can only contain up to 32 alphanumeric characters including `_` and `-`. |
63-
| cData | `string` | `undefined` | A customer payload that can be used to attach customer data to the challenge throughout its issuance and which is returned upon validation. This can only contain up to 255 alphanumeric characters including `_` and `-`. |
57+
| **Option** | **Type** | **Default** | **Description** |
58+
| ---------- | -------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
59+
| theme | `string` | `'auto'` | The widget theme. You can choose between `light`, `dark` or `auto`. |
60+
| tabIndex | `number` | `0` | The `tabindex` of Turnstile’s iframe for accessibility purposes. |
61+
| action | `string` | `undefined` | A customer value that can be used to differentiate widgets under the same `sitekey` in analytics and which is returned upon validation. This can only contain up to 32 alphanumeric characters including `_` and `-`. |
62+
| cData | `string` | `undefined` | A customer payload that can be used to attach customer data to the challenge throughout its issuance and which is returned upon validation. This can only contain up to 255 alphanumeric characters including `_` and `-`. |
6463

6564
> Read [the docs](https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/#configurations) to get more info about this options.
6665
@@ -275,9 +274,9 @@ Any contributions are greatly appreciated. If you have a suggestion that would m
275274
276275
## 💻 Development
277276
278-
- [Fork](https://github.com/marsidev/react-turnstile/fork) or clone the repo
279-
- Install dependencies with `pnpm install`
280-
- You can use `pnpm dev` to stub the library, `pnpm build` to build the library, `pnpm example:dev` to start the demo page in dev mode.
277+
- [Fork](https://github.com/marsidev/react-turnstile/fork) or clone this [repository](https://github.com/marsidev/react-turnstile).
278+
- Install dependencies with `pnpm install`.
279+
- You can use `pnpm dev` to stub the library, `pnpm build` to build the library or `pnpm example:dev` to start the demo page in development mode.
281280
282281
## Credits
283282

src/lib.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { DEFAULT_CONTAINER_ID, DEFAULT_ONLOAD_NAME, injectTurnstileScript } from
33
import { RenderParameters, TurnstileInstance, TurnstileProps } from './types'
44

55
export const Turnstile = forwardRef<TurnstileInstance, TurnstileProps>((props, ref) => {
6-
const { scriptOptions, options, siteKey, onSuccess, onExpire, onError, ...divProps } = props
7-
const { container, ...config } = options ?? {}
6+
const { scriptOptions, options, siteKey, onSuccess, onExpire, onError, id, ...divProps } = props
7+
const config = options ?? {}
88

99
const [widgetId, setWidgetId] = useState<string | undefined | null>()
1010
const [scriptLoaded, setScriptLoaded] = useState(false)
1111
const containerRef = useRef<HTMLDivElement | null>(null)
1212
const firstRendered = useRef(false)
1313

14-
const containerId = typeof container === 'string' ? container : DEFAULT_CONTAINER_ID
14+
const containerId = id ?? DEFAULT_CONTAINER_ID
1515
const onLoadCallbackName = scriptOptions?.onLoadCallbackName || DEFAULT_ONLOAD_NAME
1616
const scriptOptionsJson = JSON.stringify(scriptOptions)
1717
const configJson = JSON.stringify(config)
@@ -121,7 +121,7 @@ export const Turnstile = forwardRef<TurnstileInstance, TurnstileProps>((props, r
121121
return () => {
122122
clearInterval(timerId)
123123
}
124-
}, [configJson, scriptOptionsJson, container])
124+
}, [configJson, scriptOptionsJson])
125125

126126
useEffect(
127127
function rerenderWidget() {

src/types.d.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ interface ComponentOptions extends TurnstileBaseOptions {
8585
* @default 0
8686
*/
8787
tabIndex?: number
88-
/**
89-
* Container ID or container node that will wrap the widget iframe.
90-
* @default `cf-turnstile`
91-
*
92-
*/
93-
container?: string | HTMLElement
9488
}
9589

9690
/** Props needed for the `.render()` function */

0 commit comments

Comments
 (0)