From 0759ab6b0ae0d5df5d69bfce3faa2091c886b311 Mon Sep 17 00:00:00 2001 From: David Barri Date: Sat, 9 May 2020 13:44:51 +1000 Subject: [PATCH] Deprecate deprecated KeyboardEvent fields Closes #710 --- .../scalajs/react/CallbackOption.scala | 9 +++++ .../japgolly/scalajs/react/raw/events.scala | 38 ++++++++++++++++++- doc/changelog/1.7.0.md | 9 +++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/japgolly/scalajs/react/CallbackOption.scala b/core/src/main/scala/japgolly/scalajs/react/CallbackOption.scala index f5dc25873..99bda240f 100644 --- a/core/src/main/scala/japgolly/scalajs/react/CallbackOption.scala +++ b/core/src/main/scala/japgolly/scalajs/react/CallbackOption.scala @@ -108,6 +108,15 @@ object CallbackOption { implicit def fromCallback(c: Callback): CallbackOption[Unit] = c.toCBO + def keySwitch[A](e : ReactKeyboardEvent, + altKey : Boolean = false, + ctrlKey : Boolean = false, + metaKey : Boolean = false, + shiftKey: Boolean = false) + (switch : PartialFunction[String, CallbackTo[A]]): CallbackOption[A] = + keyEventSwitch(e, e.key, altKey, ctrlKey, metaKey, shiftKey)(switch) + + @deprecated("Use .keySwitch instead. keyCode is officially deprecated.", "1.7.0") def keyCodeSwitch[A](e : ReactKeyboardEvent, altKey : Boolean = false, ctrlKey : Boolean = false, diff --git a/core/src/main/scala/japgolly/scalajs/react/raw/events.scala b/core/src/main/scala/japgolly/scalajs/react/raw/events.scala index 55c64462d..39febf049 100644 --- a/core/src/main/scala/japgolly/scalajs/react/raw/events.scala +++ b/core/src/main/scala/japgolly/scalajs/react/raw/events.scala @@ -141,12 +141,46 @@ trait SyntheticKeyboardEvent[+DOMEventTarget <: dom.Node] extends SyntheticUIEve /** See org.scalajs.dom.extensions.KeyValue */ val key: String = js.native - /** printable keys (letters, numbers, symbols) */ + /** Non-standard. + * This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it + * will not work for every user. There may also be large incompatibilities between implementations and the behavior + * may change in the future. + * + * Deprecated. This feature is no longer recommended. + * Though some browsers might still support it, it may have already been removed from the relevant web standards, may + * be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update + * existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware + * that this feature may cease to work at any time. + * + * The charCode read-only property of the KeyboardEvent interface returns the Unicode value of a character key + * pressed during a keypress event. + */ + @deprecated("Use .key instead. See https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/charCode", "1.7.0") val charCode: Int = js.native - /** non-printable keys (modifiers, arrow keys, tab, esc) */ + /** Deprecated. This feature is no longer recommended. + * Though some browsers might still support it, it may have already been removed from the relevant web standards, may + * be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update + * existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware + * that this feature may cease to work at any time. + * + * The deprecated KeyboardEvent.keyCode read-only property represents a system and implementation dependent numerical + * code identifying the unmodified value of the pressed key. This is usually the decimal ASCII (RFC 20) or Windows + * 1252 code corresponding to the key. If the key can't be identified, this value is 0. + */ + @deprecated("See https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode", "1.7.0") val keyCode: Int = js.native + /** Deprecated. This feature is no longer recommended. + * Though some browsers might still support it, it may have already been removed from the relevant web standards, may + * be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update + * existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware + * that this feature may cease to work at any time. + * + * The which read-only property of the KeyboardEvent interface returns the numeric keyCode of the key pressed, or the + * character code (charCode) for an alphanumeric key pressed. + */ + @deprecated("See https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/which", "1.7.0") val which: Int = js.native } diff --git a/doc/changelog/1.7.0.md b/doc/changelog/1.7.0.md index 2ae8e3034..e3c8bc4d1 100644 --- a/doc/changelog/1.7.0.md +++ b/doc/changelog/1.7.0.md @@ -100,6 +100,15 @@ * `getDerivedStateFromProps[S](f: P => S)` can now be used as step 2 in the component builder, instead of calling one of the `initialState` methods and then `getDerivedStateFromProps` again later * `getDerivedStateFromPropsAndState[S](f: (P, Option[S]) => S)` can now be used as step 2 in the component builder, instead of calling one of the `initialState` methods and then `getDerivedStateFromProps` again later +* Deprecate `KeyboardEvent` fields: + * `.charCode` + * `.keyCode` + * `.which` + +* In `CallbackOption`: + * deprecate `keyCodeSwitch` + * add `keySwitch` + * Upgrade to React 16.13.1 * Add `ReactDOM.version` * Add `ReactDOMServer.version`