MCPcopy Create free account
hub / github.com/Effect-TS/effect / Input

Function Input

packages/effect/src/ui/kit/Input.ts:144–182  ·  view source on GitHub ↗
(
  h: { readonly input: InputElement<Msg> },
  options: {
    /** The caller's `h.input`, to stack a part on it. `h.input` when left out. */
    readonly element?: InputElement<Msg, R> | undefined
    readonly props: InputProps
    /** The message an edit sends, from the value the user left in the field. */
    readonly onUpdate?:
      | ((event: { readonly value: string }) => NoInfer<Msg> | undefined)
      | undefined
  }
)

Source from the content-addressed store, hash-verified

142 * @since 4.2.0
143 */
144export const Input = <Msg, R = never>(
145 h: { readonly input: InputElement<Msg> },
146 options: {
147 /** The caller's `h.input`, to stack a part on it. `h.input` when left out. */
148 readonly element?: InputElement<Msg, R> | undefined
149 readonly props: InputProps
150 /** The message an edit sends, from the value the user left in the field. */
151 readonly onUpdate?:
152 | ((event: { readonly value: string }) => NoInfer<Msg> | undefined)
153 | undefined
154 }
155): InputElement<Msg, R> => {
156 const element: InputElement<Msg, R> = options.element ?? h.input
157 const { onUpdate, props } = options
158 const disabled = props.disabled === true
159 // The writes wait for the finished input, so they come after whatever
160 // the caller chains on it, and the check sees an input handler chained
161 // after the call.
162 return element.forward((node) => {
163 // By `onUpdate` alone, not by the state: a disabled input sets no
164 // handler now, but the clash would only show once it was enabled.
165 if (onUpdate !== undefined && node.handlers.input !== undefined) {
166 throw new Error(
167 "Input: the element already handles input, which onUpdate would replace. Send the message from onUpdate"
168 )
169 }
170 const input = node
171 .value(props.value)
172 .attrs({
173 // Never set: the native `disabled` reports it.
174 "aria-disabled": undefined,
175 "data-disabled": flag(disabled)
176 })
177 .disabled(disabled)
178 return !disabled && onUpdate !== undefined
179 ? input.on("input", ({ value }) => onUpdate({ value }))
180 : input
181 })
182}

Callers 9

Input.tst.tsFile · 0.90
Field.tst.tsFile · 0.90
Field.test.tsFile · 0.90
Input.test.tsFile · 0.90
TextFieldFunction · 0.90
10_dialog-form.tsFile · 0.90
tiles.tsFile · 0.90
FormFieldFunction · 0.90
PeoplePage.tsFile · 0.90

Calls 7

flagFunction · 0.90
onUpdateFunction · 0.85
forwardMethod · 0.80
disabledMethod · 0.65
attrsMethod · 0.65
onMethod · 0.65
valueMethod · 0.45

Tested by

no test coverage detected