From e05e9719e5b7b9f385a8d0037999c8dae40dac69 Mon Sep 17 00:00:00 2001 From: Evgeniy Tokarev Date: Sat, 3 Feb 2024 05:31:42 +0200 Subject: [PATCH] Add onBeforeInput & onBeforeInputCapture --- .../src/main/scala/slinky/generator/Generator.scala | 1 + web/html.json | 12 ++++++++++++ .../main/scala/slinky/web/SyntheticInputEvent.scala | 11 +++++++++++ 3 files changed, 24 insertions(+) create mode 100644 web/src/main/scala/slinky/web/SyntheticInputEvent.scala diff --git a/generator/src/main/scala/slinky/generator/Generator.scala b/generator/src/main/scala/slinky/generator/Generator.scala index cef0c4a2..6708d40e 100644 --- a/generator/src/main/scala/slinky/generator/Generator.scala +++ b/generator/src/main/scala/slinky/generator/Generator.scala @@ -14,6 +14,7 @@ object Generator { val eventToSynthetic = Map[String, String => String]( "EventHandler" -> (t => s"slinky.core.SyntheticEvent[$t, org.scalajs.dom.Event]"), + "InputEventHandler" -> (t => s"slinky.web.SyntheticInputEvent[$t]"), "ClipboardEventHandler" -> (t => s"slinky.web.SyntheticClipboardEvent[$t]"), "CompositionEventHandler" -> (t => s"slinky.web.SyntheticCompositionEvent[$t]"), "KeyboardEventHandler" -> (t => s"slinky.web.SyntheticKeyboardEvent[$t]"), diff --git a/web/html.json b/web/html.json index 5bb7de85..accf7b81 100644 --- a/web/html.json +++ b/web/html.json @@ -2214,6 +2214,18 @@ "hasCaptureVariant" : true }, + // Input Events + { + "attributeName" : "onBeforeInput", + "attributeType" : "InputEventHandler", + "docLines" : [ + "" + ], + "compatibleTags" : null, + "withDash" : false, + "hasCaptureVariant" : true + }, + // Keyboard Events { "attributeName" : "onKeyDown", diff --git a/web/src/main/scala/slinky/web/SyntheticInputEvent.scala b/web/src/main/scala/slinky/web/SyntheticInputEvent.scala new file mode 100644 index 00000000..ae4d230f --- /dev/null +++ b/web/src/main/scala/slinky/web/SyntheticInputEvent.scala @@ -0,0 +1,11 @@ +package slinky.web + +import slinky.core.SyntheticEvent +import scala.scalajs.js +import org.scalajs.dom.InputEvent + +//https://react.dev/reference/react-dom/components/common#inputevent-handler +@js.native +trait SyntheticInputEvent[+TargetType] extends SyntheticEvent[TargetType, InputEvent] { + val data: String = js.native +}