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

SpotlightObject

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(containerIdOrConfig, {config})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.

1 or more Params
containerIdOrConfig StringObject

Configuration object or container ID

config Object
optional

Configuration object if container ID supplied in containerIdOrConfig

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}, {containerOption})Boolean

Focuses the specified component ID, container ID, element selector, 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.

0 or more Params
elem StringNode
optional

The spotlight ID or selector for either a spottable component or a spotlight container, or spottable node. If not supplied, the default container will be focused.

containerOption Object
optional
default: {}

The object including enterTo and toOuterContainer. It works when the first parameter elem is either a spotlight container ID or a spotlight container node.

Object keys for containerOption
enterTo 'last-focused''default-element''topmost'

Specifies preferred enterTo configuration.

toOuterContainer Boolean

If the proper target is not found, search one recursively to outer container.

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()Node

Returns the currently spotted control.

Returns
Node

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)ArrayNode

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

1 Param
containerId String

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

Returns
ArrayNode

The spottable elements that are wrapped by the supplied container

initialize(containerDefaults)undefined

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

1 Param
containerDefaults Object

Default configuration for new spotlight containers

Returns
undefined
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 Stringundefined

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()undefined

Pauses Spotlight

Returns
undefined
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()undefined

Resumes Spotlight

Returns
undefined
set(containerIdOrConfig, {config})undefined

Sets the config for spotlight or the specified containerID

1 or more Params
containerIdOrConfig StringObject

Configuration object or container ID

config Object
optional

Configuration object if container ID supplied in containerIdOrConfig

Returns
undefined
setActiveContainer({containerId})

Sets the currently active container.

Note: If the current container is restricted to 'self-only' and containerId is not contained within the current container then the active container will not be updated.

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})undefined

Sets or clears the default container that will receive focus.

0 or more Params
containerId String
optional

The container ID or a falsy value to clear default container

Returns
undefined
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 )false|String

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

1 Param
keyCode Number

Key code to analyze

Returns
falseString

One of 'up', 'down', 'left', 'right' or false if not a direction key

ArrayBooleanFunctionModuleNumberObjectString