A library to handle d-pad navigation in KaiOS.
npm install onyx-navigation
Fired on an element when it loses focus.
Fired on an element when it gains focus.
Fired on the focused element when the Enter key is pressed.
Fired on the focused element when the SoftLeft key is pressed.
Fired on the focused element when the SoftRight key is pressed.
Marks an element as an Onyx group.
Marks an element as an Onyx scroller. You need one of these in each Onyx group. This is the element that your items will scroll in.
Marks an element as an Onyx item. This must be a unique value per Onyx group.
When an element is focused, it gains this attribute.
This lets you tie an element to a 1-9 number key. Pressing one of these keys will fire onyx:focus
and onyx:select
on the marked element.
OnyxNavigation.startListening();
document.addEventListener('onyx:focus', (ev) => {
console.log(`Item ${ev.detail.itemId} in group ${ev.detail.groupId} focused`);
});
document.addEventListener('onyx:blur', (ev) => {
console.log(`Item ${ev.detail.itemId} in group ${ev.detail.groupId} blurred`);
});
document.addEventListener('onyx:select', (ev) => {
console.log(`Item ${ev.detail.itemId} in group ${ev.detail.groupId} selected`);
});
document.addEventListener('onyx:softleft', (ev) => {
console.log(`Item ${ev.detail.itemId} in group ${ev.detail.groupId} softleft`);
});
document.addEventListener('onyx:softright', (ev) => {
console.log(`Item ${ev.detail.itemId} in group ${ev.detail.groupId} softright`);
});
<div class="content" data-onyx-group-id="main">
<div class="scroller" data-onyx-scroller>
<div class="row">
<div class="item" data-onyx-item-id="row1_item1" data-onyx-shortcut="1"></div>
<div class="item" data-onyx-item-id="row1_item2" data-onyx-shortcut="2"></div>
<div class="item" data-onyx-item-id="row1_item3" data-onyx-shortcut="3"></div>
</div>
<div class="row">
<div class="item" data-onyx-item-id="row2_item1" data-onyx-shortcut="4"></div>
<div class="item" data-onyx-item-id="row2_item2" data-onyx-shortcut="5"></div>
<div class="item" data-onyx-item-id="row2_item3" data-onyx-shortcut="6"></div>
</div>
<div class="row">
<div class="item" data-onyx-item-id="row3_item1" data-onyx-shortcut="7"></div>
<div class="item" data-onyx-item-id="row3_item2" data-onyx-shortcut="8"></div>
<div class="item" data-onyx-item-id="row3_item3" data-onyx-shortcut="9"></div>
</div>
</div>
</div>