spotlight

Exports the spotlight.Spotlight object used for controlling spotlight behavior and the spotlight.Spotlight.getDirection function for mapping a keycode to a spotlight direction.

The default export is spotlight.Spotlight.

import spotlight from '@enact/spotlight';

Members

Spotlight

Provides 5-way navigation and focus support

import Spotlight from '@enact/Spotlight';

// get the currently focused component
const current = Spotlight.getCurrent();

// focus an element by CSS selector
Spotlight.focus('.my-custom-class');

// is `current` focusable?
const isFocused = Spotlight.isSpottable(current);
Statics
add(param1, param2)String

Adds the config for a new container. The container ID may be passed in the configuration object. If no container ID is supplied, a new container ID will be generated.

2 Params
param1 StringObject

Configuration object or container ID

param2 Object

Configuration object if container ID supplied in param1

Returns
String

The container ID of the container

disableSelector(containerId)Boolean

Disables the selector rules of the specified container

1 Param
containerId String

Container ID selector rules to disable

Returns
Boolean

true if container's selector rules are disabled, false if container does not exist

enableSelector(containerId)Boolean

Enables the selector rules of the specified container

1 Param
containerId String

Container ID selector rules to enable

Returns
Boolean

true if container's selector rules are enabled, false if container does not exist

focus(elem)Boolean

Focuses the specified element selector or container ID or the default container. If Spotlight is in pointer mode, focus is not changed but elem will be set as the last focused element of its spotlight containers.

1 Param
elem StringObject

Element selector or the container ID. If not supplied, the default container will be focused.

Returns
Boolean

true if focus successful, false if not.

getActiveContainer()String

Gets the currently active container.

Returns
String

The id of the currently active container

getCurrent()Object

Returns the currently spotted control.

Returns
Object

The control that currently has focus, if available

getPointerMode()Boolean

Gets the current pointer mode

Returns
Boolean

true if spotlight is in pointer mode

getSpottableDescendants({containerId})NodeList

Returns a list of spottable elements wrapped by the supplied container.

0 or more Params
containerId String
optional

The id of the container used to determine the list of spottable elements

Returns
NodeList

The spottable elements that are wrapped by the supplied container

initialize(containerDefaults)

Initializes Spotlight. This is generally handled by spotlight/SpotlightRootDecorator.SpotlightRootDecorator.

1 Param
containerDefaults
isMuted(elem)Boolean

Gets the muted mode value of a spottable element.

1 Param
elem Object

The dom element used to determine the muted status.

Returns
Boolean

true if the passed-in control is in muted mode.

isPaused()Boolean

Determines whether Spotlight is currently paused.

Returns
Boolean

true if Spotlight is currently paused.

isSpottable(elem)Boolean

Determines whether an element is spottable.

1 Param
elem Object

The dom element used to determine the spottable status.

Returns
Boolean

true if the element being evaluated is currently spottable.

move(direction, selector)Boolean

Moves focus to the next spottable control in the direction specified. Optionally, a source element selector may be supplied as the starting point.

2 Params
direction String

Direction to move, one of 'left', 'right', 'up' or 'down'

selector String

If supplied, the element to move from. If not supplied, the currently focused item will be used.

Returns
Boolean

true if focus successful, false if not.

pause()

Pauses Spotlight

remove(containerId)Boolean

Removes a container from Spotlight

1 Param
containerId String

Container ID to remove

Returns
Boolean

true if container removed, false if container does not exist

resume()

Resumes Spotlight

set(param1, param2)

Sets the config for spotlight or the specified containerID

2 Params
param1 StringObject

Configuration object or container ID

param2 Object

Configuration object if container ID supplied in param1

setActiveContainer({containerId})

Sets the currently active container.

0 or more Params
containerId String
optional

The id of the currently active container. If this is not provided, the root container is set as the currently active container.

setDefaultContainer(containerId)

Sets or clears the default container that will receive focus.

1 Param
containerId String

The container ID or a falsy value to clear default container

setPointerMode(pointerMode)

Sets the current pointer mode

1 Param
pointerMode Boolean

The value of the pointer mode. This determines how spotlight manages focus change behaviors.

terminate()

Terminates Spotlight. This is generally handled by spotlight.SpotlightRootDecorator.

getDirectionFunction

getDirection(keyCode)

Translates keyCodes into 5-way direction descriptions (e.g. 'down')

1 Param
keyCode Number

Key code to analyze

ArrayBooleanFunctionModuleNumberObjectString