Skip to content

Commit b9d915e

Browse files
committed
greptile followups
1 parent 3e42fd5 commit b9d915e

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

  • packages/reflex-components-internal/src/reflex_components_internal/components/base

packages/reflex-components-internal/src/reflex_components_internal/components/base/otp_field.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,38 @@ def create(cls, *children, **props) -> BaseUIComponent:
156156
157157
Renders a Root with `length` Input slots when no children are
158158
provided. Pass children explicitly to customize layout (e.g. inserting
159-
a Separator between groups of inputs).
159+
a Separator between groups of inputs); `length` is still required and
160+
forwarded to the underlying Root.
160161
161162
Args:
162163
*children: Optional children to include in place of the default inputs.
163164
**props: Additional properties to apply to the OTP field root.
164165
165166
Returns:
166167
The OTP field component.
168+
169+
Raises:
170+
ValueError: If `length` is missing when children are supplied, or
171+
if `length` is not a positive integer when children are
172+
auto-generated.
173+
TypeError: If `length` is not an integer when children are
174+
auto-generated (a Var can only be used with explicit children).
167175
"""
168-
if not children:
169-
length = props.get("length", 6)
170-
if not isinstance(length, int):
176+
if children:
177+
if "length" not in props:
178+
msg = "OTP field `length` is required when passing children explicitly."
179+
raise ValueError(msg)
180+
else:
181+
length = props.setdefault("length", 6)
182+
if not isinstance(length, int) or isinstance(length, bool):
171183
msg = (
172184
"OTP field high-level wrapper requires a static integer `length`."
173185
" Pass children explicitly for dynamic lengths."
174186
)
175187
raise TypeError(msg)
188+
if length <= 0:
189+
msg = "OTP field `length` must be a positive integer."
190+
raise ValueError(msg)
176191
children = tuple(OTPFieldInput.create() for _ in range(length))
177192

178193
return OTPFieldRoot.create(*children, **props)

0 commit comments

Comments
 (0)