Skip to content

Item & Interactable ​

Two support components carry the properties that most widgets share. Neither registers a primitive — they are attached to the entities that use them, and the widget primitives map their width, height, margin, key, etc. attributes onto them.

ComponentPrimitiveDescription
sxr-item<none>Used by other components for common properties like height and width
sxr-interactable<none>Used by other components to define onclick behavior

sxr-item Component ​

Shared dimensions, depth, margin and bevel.

PropertyDescriptionDefault Value
typeWidget type identifier''
widthWidth of item1
heightHeight of item1
baseDepthDepth of the item base0.01
depthDepth of item0.02
gapGap between item and base0.025
radiusCorner radius of the item base0
marginMargin around item0 0 0 0
bevelIf true, the item bevel is enabledfalse
bevelSegmentsSegments of the item bevel5
stepsSteps of the item bevel2
bevelSizeSize of the item bevel0.1
bevelOffsetOffset of the item bevel0
bevelThicknessThickness of the item bevel0.1

margin is a vec4 and follows the CSS shorthand order (top, right, bottom, left).

Read the current values at runtime with the SXR.getItem helper, which falls back to these documented defaults when the widget is placed on an ordinary entity.

sxr-interactable Component ​

Click/hover callbacks and keyboard shortcut registration.

PropertyDescriptionDefault Value
clickActionName of a global function called on click
hoverActionName of a global function called on hover
keyTextual shortcut key that activates the widget (e.g. e)
keyCodeLegacy numeric shortcut key (e.g. 32 for Space)-1

Keyboard registry ​

A single window-level keydown listener dispatches to all registered sxr-interactable instances, rather than one global capture listener per widget. The listener is attached on the first registration and removed when the last one unregisters.

  • Multiple widgets bound to the same key all fire — bind distinct keys per widget.
  • Shortcuts are ignored while the user is typing into an editable surface, during IME composition, and for auto-repeated keydowns.
  • key works independently of the legacy numeric keyCode.
  • When a widget's own shortcut key matches the focused key press, the widget skips its own focused Enter/Space handling, preventing duplicate activation.

Shortcut activation emits a click event with a source: 'keyboard' detail, along with the key and keyCode:

js
document.querySelector('a-sxr-button').addEventListener('click', (e) => {
  console.log(e.detail.source) // 'keyboard'
  console.log(e.detail.key)     // 'e'
})

Instance methods ​

MethodPurpose
matchesEvent(event)True when this instance's key / keyCode matches the event
setClickAction(action)Rebind the click callback name