From 2cca18728e7d8a5691df6598629ba21020e22898 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Mon, 29 Apr 2019 13:52:15 -0700 Subject: [PATCH] React Events: add onFocusVisibleChange to Focus (#15516) Called when focus visibility changes. Focus is only considered visible if a focus event occurs after keyboard navigation. This provides a way for people to provide visual focus styles for keyboard accessible UIs without those styles appearing if focus is triggered by mouse, touch, pen. --- packages/react-events/docs/Focus.md | 39 +++++-- packages/react-events/src/Focus.js | 107 +++++++++++++++++- .../src/__tests__/Focus-test.internal.js | 68 +++++++++++ .../src/__tests__/Press-test.internal.js | 8 +- 4 files changed, 202 insertions(+), 20 deletions(-) diff --git a/packages/react-events/docs/Focus.md b/packages/react-events/docs/Focus.md index ea4151bf7302d..1fef78e370ff4 100644 --- a/packages/react-events/docs/Focus.md +++ b/packages/react-events/docs/Focus.md @@ -1,21 +1,31 @@ # Focus The `Focus` module responds to focus and blur events on its child. Focus events -are dispatched for `mouse`, `pen`, `touch`, and `keyboard` -pointer types. +are dispatched for all input types, with the exception of `onFocusVisibleChange` +which is only dispatched when focusing with a keyboard. Focus events do not propagate between `Focus` event responders. ```js // Example -const TextField = (props) => ( - - - -); +const Button = (props) => { + const [ focusVisible, setFocusVisible ] = useState(false); + + return ( + +