@@ -11,6 +11,8 @@ import {
1111 setPortalAttribute ,
1212 setVirtualParent ,
1313 FocusRectsProvider ,
14+ FocusRectsContext ,
15+ IsFocusVisibleClassName ,
1416} from '../../Utilities' ;
1517import {
1618 registerLayer ,
@@ -24,6 +26,14 @@ import type { ILayerProps, ILayerStyleProps, ILayerStyles } from './Layer.types'
2426
2527const getClassNames = classNamesFunction < ILayerStyleProps , ILayerStyles > ( ) ;
2628
29+ const getFocusVisibility = ( providerRef ?: React . RefObject < HTMLElement > ) => {
30+ if ( providerRef ?. current ) {
31+ return providerRef . current . classList . contains ( IsFocusVisibleClassName ) ;
32+ }
33+
34+ return false ;
35+ } ;
36+
2737export const LayerBase : React . FunctionComponent < ILayerProps > = React . forwardRef < HTMLDivElement , ILayerProps > (
2838 ( props , ref ) => {
2939 const registerPortalEl = usePortalCompat ( ) ;
@@ -32,11 +42,24 @@ export const LayerBase: React.FunctionComponent<ILayerProps> = React.forwardRef<
3242 const mergedRef = useMergedRefs ( rootRef , ref ) ;
3343 const layerRef = React . useRef < HTMLDivElement > ( ) ;
3444 const fabricElementRef = React . useRef < HTMLDivElement > ( null ) ;
45+ const focusContext = React . useContext ( FocusRectsContext ) ;
3546
3647 // Tracks if the layer mount events need to be raised.
3748 // Required to allow the DOM to render after the layer element is added.
3849 const [ needRaiseLayerMount , setNeedRaiseLayerMount ] = React . useState ( false ) ;
3950
51+ // Sets the focus visible className when the FocusRectsProvider for the layer is rendered
52+ // This allows the current focus visibility style to be carried over to the layer content
53+ const focusRectsRef = React . useCallback (
54+ el => {
55+ const isFocusVisible = getFocusVisibility ( focusContext ?. providerRef ) ;
56+ if ( el && isFocusVisible ) {
57+ el . classList . add ( IsFocusVisibleClassName ) ;
58+ }
59+ } ,
60+ [ focusContext ] ,
61+ ) ;
62+
4063 const {
4164 children,
4265 className,
@@ -52,7 +75,7 @@ export const LayerBase: React.FunctionComponent<ILayerProps> = React.forwardRef<
5275 theme,
5376 } = props ;
5477
55- const fabricRef = useMergedRefs ( fabricElementRef , fabricProps ?. ref ) ;
78+ const fabricRef = useMergedRefs ( fabricElementRef , fabricProps ?. ref , focusRectsRef ) ;
5679
5780 const classNames = getClassNames ( styles ! , {
5881 theme : theme ! ,
0 commit comments