Skip to content

Commit

Permalink
item -> itemMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
noraleonte committed Apr 4, 2024
1 parent f563394 commit 2c7e7de
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export const useTreeViewExpansion: TreeViewPlugin<UseTreeViewExpansionSignature>
);

const expandAllSiblings = (event: React.KeyboardEvent, itemId: string) => {
const item = instance.getItemMeta(itemId);
const siblings = instance.getChildrenIds(item.parentId);
const itemMeta = instance.getItemMeta(itemId);
const siblings = instance.getChildrenIds(itemMeta.parentId);

const diff = siblings.filter(
(child) => instance.isItemExpandable(child) && !instance.isItemExpanded(child),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const useTabbableItemId = (
selectedItems: string | string[] | null,
) => {
const isItemVisible = (itemId: string) => {
const item = instance.getItemMeta(itemId);
return item && (item.parentId == null || instance.isItemExpanded(item.parentId));
const itemMeta = instance.getItemMeta(itemId);
return itemMeta && (itemMeta.parentId == null || instance.isItemExpanded(itemMeta.parentId));
};

let tabbableItemId: string | null | undefined;
Expand Down Expand Up @@ -62,13 +62,15 @@ export const useTreeViewFocus: TreeViewPlugin<UseTreeViewFocusSignature> = ({
);

const isItemVisible = (itemId: string) => {
const item = instance.getItemMeta(itemId);
return item && (item.parentId == null || instance.isItemExpanded(item.parentId));
const itemMeta = instance.getItemMeta(itemId);
return itemMeta && (itemMeta.parentId == null || instance.isItemExpanded(itemMeta.parentId));
};

const innerFocusItem = (event: React.SyntheticEvent | null, itemId: string) => {
const item = instance.getItemMeta(itemId);
const itemElement = document.getElementById(instance.getTreeItemId(itemId, item.idAttribute));
const itemMeta = instance.getItemMeta(itemId);
const itemElement = document.getElementById(
instance.getTreeItemId(itemId, itemMeta.idAttribute),
);
if (itemElement) {
itemElement.focus();
}
Expand Down Expand Up @@ -106,10 +108,10 @@ export const useTreeViewFocus: TreeViewPlugin<UseTreeViewFocusSignature> = ({
return;
}

const item = instance.getItemMeta(state.focusedItemId);
if (item) {
const itemMeta = instance.getItemMeta(state.focusedItemId);
if (itemMeta) {
const itemElement = document.getElementById(
instance.getTreeItemId(state.focusedItemId, item.idAttribute),
instance.getTreeItemId(state.focusedItemId, itemMeta.idAttribute),
);
if (itemElement) {
itemElement.blur();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,20 @@ export const useTreeViewItems: TreeViewPlugin<UseTreeViewItemsSignature> = ({
return false;
}

let item = instance.getItemMeta(itemId);
let itemMeta = instance.getItemMeta(itemId);

// This can be called before the item has been added to the item map.
if (!item) {
if (!itemMeta) {
return false;
}

if (item.disabled) {
if (itemMeta.disabled) {
return true;
}

while (item.parentId != null) {
item = instance.getItemMeta(item.parentId);
if (item.disabled) {
while (itemMeta.parentId != null) {
itemMeta = instance.getItemMeta(itemMeta.parentId);
if (itemMeta.disabled) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export const getPreviousItem = (
instance: TreeViewInstance<[UseTreeViewItemsSignature, UseTreeViewExpansionSignature]>,
itemId: string,
) => {
const item = instance.getItemMeta(itemId);
const siblings = instance.getNavigableChildrenIds(item.parentId);
const itemMeta = instance.getItemMeta(itemId);
const siblings = instance.getNavigableChildrenIds(itemMeta.parentId);
const itemIndex = siblings.indexOf(itemId);

if (itemIndex === 0) {
return item.parentId;
return itemMeta.parentId;
}

let currentItem: string = siblings[itemIndex - 1];
Expand All @@ -39,18 +39,18 @@ export const getNextItem = (
return instance.getNavigableChildrenIds(itemId)[0];
}

let item = instance.getItemMeta(itemId);
while (item != null) {
let itemMeta = instance.getItemMeta(itemId);
while (itemMeta != null) {
// Try to get next sibling
const siblings = instance.getNavigableChildrenIds(item.parentId);
const nextSibling = siblings[siblings.indexOf(item.id) + 1];
const siblings = instance.getNavigableChildrenIds(itemMeta.parentId);
const nextSibling = siblings[siblings.indexOf(itemMeta.id) + 1];

if (nextSibling) {
return nextSibling;
}

// If the sibling does not exist, go up a level to the parent and try again.
item = instance.getItemMeta(item.parentId!);
itemMeta = instance.getItemMeta(itemMeta.parentId!);
}

return null;
Expand Down

0 comments on commit 2c7e7de

Please sign in to comment.