spotlight/Spottable
Adds spottability to components.
Interactive Demo
Section titled “Interactive Demo ”Members
Section titled “Members ”Spottable Higher-Order Component
Section titled “Spottable   Higher-Order Component ”Constructs a Spotlight 5-way navigation-enabled higher-order component.
Note: This HoC passes a number of props to the wrapped component that should be passed to the main DOM node.
Example:
const Component = ({myProp, ...rest}) => (
<div {...rest}>{myProp}</div>
);
...
const SpottableComponent = Spottable(Component);When a component receives spotlight focus, the data-spotlight-focused attribute is
automatically applied to its DOM node and removed on blur. This provides a stable CSS hook
for styling focused components without any additional configuration:
[data-spotlight-focused] {
outline: 3px solid var(--my-focus-color);
}Or within a CSS Modules component stylesheet:
.button {
&[data-spotlight-focused] {
.bg {
background-color: var(--my-focus-bg-color);
}
}
}For an app-wide focus class, see spotlight/SpotlightRootDecoratorspotlight/SpotlightRootDecorator.SpotlightRootDecorator
and its focusEffectClass config option.
Configuration
emulateMouse
Section titled “emulateMouse”Whether or not the component should emulate mouse events as a response to Spotlight 5-way events.
Default: trueProperties added to wrapped component
disabled
Section titled “disabled”Whether or not the component is in a disabled state.
Default: falsehandleForceUpdate
Section titled “handleForceUpdate”The handler to force update the component.
onSpotlightDisappear
Section titled “onSpotlightDisappear”The handler to run when the component is removed while retaining focus.
onSpotlightDown
Section titled “onSpotlightDown”The handler to run when the 5-way down key is pressed.
onSpotlightLeft
Section titled “onSpotlightLeft”The handler to run when the 5-way left key is pressed.
onSpotlightRight
Section titled “onSpotlightRight”The handler to run when the 5-way right key is pressed.
onSpotlightUp
Section titled “onSpotlightUp”The handler to run when the 5-way up key is pressed.
selectionKeys
Section titled “selectionKeys”An array of numbers representing keyCodes that should trigger mouse event
emulation when emulateMouse is true. If a keyCode equals a directional
key, then default 5-way navigation will be prevented when that key is pressed.
spotlightDisabled
Section titled “spotlightDisabled”When true, the component cannot be navigated using spotlight.
spotlightId
Section titled “spotlightId”Used to identify this component within the Spotlight system
tabIndex
Section titled “tabIndex”The tabIndex of the component. This value will default to -1 if left unset and the control is spottable.
spottableClass string
Section titled “spottableClass   string ”The class name for spottable components. In general, you do not need to directly access this class