OtpField
A bounded one-time-code editor made from individually styled input cells.
Loading interactive demo…
func OtpFieldExample() *ui.Element {
code, setCode := ui.CreateSignal("")
field := ui.NewOtpField(ui.OtpFieldRootProps{Value: code, Length: 6, ValidationType: "numeric", OnValueChange: func(next string, _ *native.Event) {
setCode(next)
}, OnComplete: func(value string, _ *native.Event) {
fmt.Println("Complete:", value)
}})
inputs := make([]*ui.Element, 0, 6)
for index := range 6 {
inputs = append(inputs, field.Input(index))
}
return field.Root().Children(inputs)
}#Import
Import ui from github.com/egoist/quickgui/go/ui.
import (
"fmt"
"github.com/egoist/quickgui/go/native"
"github.com/egoist/quickgui/go/ui"
)#Usage
func OtpFieldExample() *ui.Element {
code, setCode := ui.CreateSignal("")
field := ui.NewOtpField(ui.OtpFieldRootProps{Value: code, Length: 6, ValidationType: "numeric", OnValueChange: func(next string, _ *native.Event) {
setCode(next)
}, OnComplete: func(value string, _ *native.Event) {
fmt.Println("Complete:", value)
}})
inputs := make([]*ui.Element, 0, 6)
for index := range 6 {
inputs = append(inputs, field.Input(index))
}
return field.Root().Children(inputs)
}#Anatomy
otpField.RoototpField.InputotpField.Separator
#API reference
Expand an entry for its description and complete signature. A dash means no declaration default is documented.
NewOtpField
View sourceui.NewOtpField(props ...OtpFieldRootProps) *OtpFieldComponentNewOtpField declares a OtpField instance. Optional props provide initial settings.
Reffunc(*native.Node)—
Receives the retained native node after construction. Keep imperative work in event or lifecycle callbacks.
func(*native.Node)View sourceStyleany—
Reusable layout, typography, color, and interaction-state styles. Build with ui.Style() and compose with Merge.
anyView sourceChildrenPartChildren—
Content mounted inside the component. Compound child callbacks run after the parent context exists.
PartChildrenView sourceDisabledany—
Prevents activation and exposes the disabled state to accessibility. Compound parts inherit a disabled root.
anyView sourceRolestring—
FocusOnPointerany—
Groupany—
AriaLabelany—
Accessible name, especially for icon-only controls or controls without a visible label.
anyView sourceTabIndex*float64—
Controls sequential keyboard focus order. Omit to retain the component’s default focus behavior.
*float64View sourceOnClickfunc(*native.Event)—
Called after QuickGUI resolves an activation, including supported keyboard activation.
func(*native.Event)View sourceOnDoubleClickfunc(*native.Event)—
Callback for double click. The signature below lists the event payload.
func(*native.Event)View sourceOnContextMenufunc(*native.Event)—
Callback for context menu. The signature below lists the event payload.
func(*native.Event)View sourceOnPointerfunc(*native.Event)—
OnMouseEnterfunc(*native.Event)—
Callback for mouse enter. The signature below lists the event payload.
func(*native.Event)View sourceOnMouseLeavefunc(*native.Event)—
Callback for mouse leave. The signature below lists the event payload.
func(*native.Event)View sourceOnMouseDownfunc(*native.Event)—
OnMouseUpfunc(*native.Event)—
OnKeyDownfunc(*native.Event)—
OnKeyUpfunc(*native.Event)—
OnFocusfunc(*native.Event)—
OnBlurfunc(*native.Event)—
Valuefunc() string—
The current controlled value. Update application state from the change callback to accept a new value.
func() stringView sourceDefaultValuestring—
Initial value for uncontrolled state. Use Value when the application should own subsequent changes.
stringView sourceLengthany—
ValidationTypestring—
Mask*bool—
ReadOnlybool—
Preserves the current value while keeping the control available for focus and inspection.
boolView sourceRequiredbool—
AutoSubmitstring—
OnValueChangefunc(string, *native.Event)—
Reports an accepted value change. Use the callback payload to update controlled state.
func(string, *native.Event)View sourceOnCompletefunc(string, *native.Event)—
Callback for complete. The signature below lists the event payload.
func(string, *native.Event)View sourceOtpField.Disabled
View sourceotpField.Disabled(value any) *OtpFieldComponentPrevents activation and exposes the disabled state to accessibility. Compound parts inherit a disabled root.
OtpField.Value
View sourceotpField.Value(value any) *OtpFieldComponentThe current controlled value. Update application state from the change callback to accept a new value.
OtpField.DefaultValue
View sourceotpField.DefaultValue(value string) *OtpFieldComponentInitial value for uncontrolled state. Use Value when the application should own subsequent changes.
OtpField.Length
View sourceotpField.Length(value any) *OtpFieldComponentNumber of one-time-code input slots, bounded to twelve.
OtpField.ValidationType
View sourceotpField.ValidationType(value string) *OtpFieldComponentValidation strategy applied to the field.
OtpField.Mask
View sourceotpField.Mask(value bool) *OtpFieldComponentWhether the input conceals its entered value.
OtpField.ReadOnly
View sourceotpField.ReadOnly(value bool) *OtpFieldComponentPreserves the current value while keeping the control available for focus and inspection.
OtpField.Required
View sourceotpField.Required(value bool) *OtpFieldComponentMarks the control as required for validation and accessibility.
OtpField.AutoSubmit
View sourceotpField.AutoSubmit(value string) *OtpFieldComponentSubmits the one-time code after every required cell has a value.
OtpField.OnValueChange
View sourceotpField.OnValueChange(value func(string, *native.Event)) *OtpFieldComponentReports an accepted value change. Use the callback payload to update controlled state.
OtpField.OnComplete
View sourceotpField.OnComplete(value func(string, *native.Event)) *OtpFieldComponentCallback for complete. The signature below lists the event payload.
OtpField.Root
View sourceotpField.Root() *ElementConfigures root for this part. The declared type and source define the accepted value.
OtpField.Input
View sourceotpField.Input(value int, options ...OtpFieldInputProps) *ElementConfigures input for this part. The declared type and source define the accepted value.
OtpField.InputWith
View sourceotpField.InputWith(props OtpFieldInputProps) *ElementInputWith supplies explicit properties for this part.
Reffunc(*native.Node)—
Receives the retained native node after construction. Keep imperative work in event or lifecycle callbacks.
func(*native.Node)View sourceStyleany—
Reusable layout, typography, color, and interaction-state styles. Build with ui.Style() and compose with Merge.
anyView sourceChildrenPartChildren—
Content mounted inside the component. Compound child callbacks run after the parent context exists.
PartChildrenView sourceDisabledany—
Prevents activation and exposes the disabled state to accessibility. Compound parts inherit a disabled root.
anyView sourceRolestring—
FocusOnPointerany—
Groupany—
AriaLabelany—
Accessible name, especially for icon-only controls or controls without a visible label.
anyView sourceTabIndex*float64—
Controls sequential keyboard focus order. Omit to retain the component’s default focus behavior.
*float64View sourceOnClickfunc(*native.Event)—
Called after QuickGUI resolves an activation, including supported keyboard activation.
func(*native.Event)View sourceOnDoubleClickfunc(*native.Event)—
Callback for double click. The signature below lists the event payload.
func(*native.Event)View sourceOnContextMenufunc(*native.Event)—
Callback for context menu. The signature below lists the event payload.
func(*native.Event)View sourceOnPointerfunc(*native.Event)—
OnMouseEnterfunc(*native.Event)—
Callback for mouse enter. The signature below lists the event payload.
func(*native.Event)View sourceOnMouseLeavefunc(*native.Event)—
Callback for mouse leave. The signature below lists the event payload.
func(*native.Event)View sourceOnMouseDownfunc(*native.Event)—
OnMouseUpfunc(*native.Event)—
OnKeyDownfunc(*native.Event)—
OnKeyUpfunc(*native.Event)—
OnFocusfunc(*native.Event)—
OnBlurfunc(*native.Event)—
Typestring—
Valueany—
The current controlled value. Update application state from the change callback to accept a new value.
anyView sourcePlaceholderstring—
Multilinebool—
OnInputfunc(*native.Event)—
Receives edits from the text control. Write the new text into the controlled value.
func(*native.Event)View sourceOnChangefunc(*native.Event)—
OnSubmitfunc(*native.Event)—
Indexint—
OtpField.Separator
View sourceotpField.Separator(value int, options ...OtpFieldSeparatorProps) *ElementConfigures separator for this part. The declared type and source define the accepted value.
OtpField.SeparatorWith
View sourceotpField.SeparatorWith(props OtpFieldSeparatorProps) *ElementSeparatorWith supplies explicit properties for this part.
Reffunc(*native.Node)—
Receives the retained native node after construction. Keep imperative work in event or lifecycle callbacks.
func(*native.Node)View sourceStyleany—
Reusable layout, typography, color, and interaction-state styles. Build with ui.Style() and compose with Merge.
anyView sourceChildrenPartChildren—
Content mounted inside the component. Compound child callbacks run after the parent context exists.
PartChildrenView sourceDisabledany—
Prevents activation and exposes the disabled state to accessibility. Compound parts inherit a disabled root.
anyView sourceRolestring—
FocusOnPointerany—
Groupany—
AriaLabelany—
Accessible name, especially for icon-only controls or controls without a visible label.
anyView sourceTabIndex*float64—
Controls sequential keyboard focus order. Omit to retain the component’s default focus behavior.
*float64View sourceOnClickfunc(*native.Event)—
Called after QuickGUI resolves an activation, including supported keyboard activation.
func(*native.Event)View sourceOnDoubleClickfunc(*native.Event)—
Callback for double click. The signature below lists the event payload.
func(*native.Event)View sourceOnContextMenufunc(*native.Event)—
Callback for context menu. The signature below lists the event payload.
func(*native.Event)View sourceOnPointerfunc(*native.Event)—
OnMouseEnterfunc(*native.Event)—
Callback for mouse enter. The signature below lists the event payload.
func(*native.Event)View sourceOnMouseLeavefunc(*native.Event)—
Callback for mouse leave. The signature below lists the event payload.
func(*native.Event)View sourceOnMouseDownfunc(*native.Event)—
OnMouseUpfunc(*native.Event)—
OnKeyDownfunc(*native.Event)—
OnKeyUpfunc(*native.Event)—
OnFocusfunc(*native.Event)—
OnBlurfunc(*native.Event)—
Index*int—
Element
View sourcepart.Child(content).Style(style)Every part returns a fluent element. Strings, numbers, elements, and deferred child factories compose directly.
ChildChild(child any) *Element—
Child appends content and returns this element. Content can be an element, native node, scalar, accessor, or node-returning construction callback.
Child(child any) *ElementView sourceChildrenChildren(children ...any) *Element—
Children appends multiple children in order without replacing existing content. It also accepts []any, []*Element, and []*native.Node slices as arguments. Read the retained child nodes through element.Node.Children.
Children(children ...any) *ElementView sourceStyleStyle(style StyleBuilder) *Element—
Style merges a reusable style. Scalar accessors retain independent native bindings.
Style(style StyleBuilder) *ElementView sourceOnClickOnClick(handler func()) *Element—
OnClick handles a click without an unused event parameter.
OnClick(handler func()) *ElementView sourceRefRef(handler func(*native.Node)) *Element—
Ref exposes the native handle once at this point in the declaration chain.
Ref(handler func(*native.Node)) *ElementView source