Skip to content

Commit

Permalink
Add option of a text change callback
Browse files Browse the repository at this point in the history
  • Loading branch information
cquiroz committed Dec 18, 2024
1 parent 457cc4a commit cc76f01
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final case class FormInputTextAreaView[V[_]](
autoResize: js.UndefOr[Boolean] = js.undefined,
tooltip: js.UndefOr[VdomNode] = js.undefined,
tooltipPlacement: floatingui.Placement = floatingui.Placement.Top,
onTextChange: String => Callback = _ => Callback.empty,
modifiers: Seq[TagMod] = Seq.empty
)(using val vl: ViewLike[V])
extends ReactFnProps(FormInputTextAreaView.component):
Expand All @@ -42,10 +43,13 @@ object FormInputTextAreaView:

private type Props[V[_]] = FormInputTextAreaView[V]

private def onChange[V[_]](valueView: View[String]): ReactEventFromTextArea => Callback =
private def onChange[V[_]](
valueView: View[String],
onTextChange: String => Callback
): ReactEventFromTextArea => Callback =
(e: ReactEventFromTextArea) => {
val v = e.target.value
valueView.set(v)
valueView.set(v) *> onTextChange(v)
}

private def onBlur[V[_]](props: Props[V], valueView: View[String]): Callback =
Expand All @@ -68,7 +72,7 @@ object FormInputTextAreaView:
props.tooltipPlacement,
props.modifiers
)(
^.onChange ==> onChange[V](valueView),
^.onChange ==> onChange[V](valueView, props.onTextChange),
^.onBlur --> onBlur(props, valueView)
)
)
Expand Down

0 comments on commit cc76f01

Please sign in to comment.