Skip to content

Commit

Permalink
feat(ui5-calendar-legend): address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
hinzzx committed Nov 14, 2023
1 parent 6c30084 commit a9a52dd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/main/src/CalendarLegend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ class CalendarLegend extends UI5Element {

_onItemKeyDown(e: KeyboardEvent) {
const items = this.focusableElements;
const totalItems = items.length;
const itemsCount = items.length;
const currentItem = e.target as CalendarLegendItem;
const currentIndex = items.indexOf(currentItem);

if (isDown(e)) {
e.preventDefault();
const nextIndex = currentIndex + 1;

if (nextIndex < totalItems) {
if (nextIndex < itemsCount) {
this._itemNavigation.setCurrentItem(items[nextIndex]);
this._itemNavigation._focusCurrentItem();
}
Expand All @@ -131,7 +131,12 @@ class CalendarLegend extends UI5Element {
let allFocusableItems = [...this.shadowRoot!.querySelectorAll<CalendarLegendItem>("[ui5-calendar-legend-item]"), ...this.legendItems];
const rearrangedItems: Array<CalendarLegendItem> = [];

// Rearrange items' order
/**
* Rearrange items for better keyboard navigation.
* Resolves uneven indexing in the 2-column display (e.g., [0, 2, 4, 6, 8, 10, 1, 3, 5, 7, 9]),
* which ensures a linear and logical navigation sequence
* for the desired itemNavigation behaviour.
*/
allFocusableItems.forEach(item => rearrangedItems.push(item));

const itemsFirstColumn = rearrangedItems.filter((item, index) => index % 2 === 0);
Expand Down

0 comments on commit a9a52dd

Please sign in to comment.