Skip to content

Commit

Permalink
Refactor MenuItem component to improve active state management and st…
Browse files Browse the repository at this point in the history
…yling

- Enhanced the logic for determining active menu items, allowing for accurate representation of active states for both parent and child items.
- Updated the CSS styles for the expand icon to reflect active states, improving visual feedback for user interactions.
- Improved code clarity by encapsulating active state logic within a dedicated function, enhancing maintainability.

These changes significantly enhance the user experience by providing clearer navigation cues within the Chat interface.
  • Loading branch information
trheyi committed Dec 23, 2024
1 parent 976b503 commit de50804
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 12 additions & 3 deletions packages/xgen/layouts/wrappers/Chat/Container/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,16 @@ const MenuItem: FC<{
}> = ({ item, level, expanded, activeId, onToggle, onSelect, searchTerm }) => {
const hasChildren = item.children && item.children.length > 0
const isExpanded = expanded[item.id]
const isActive = activeId === item.id

// Check if current item or any of its children are active
const isActive = (currentItem: MenuItem): boolean => {
if (currentItem.id === activeId) return true
if (currentItem.children) {
return currentItem.children.some((child) => isActive(child))
}
return false
}

const matchesSearch = item.name.toLowerCase().includes(searchTerm.toLowerCase())
const hasMatchingChildren =
item.children?.some((child) => child.name.toLowerCase().includes(searchTerm.toLowerCase())) || false
Expand All @@ -204,7 +213,7 @@ const MenuItem: FC<{
className={clsx('menu-item', {
expanded: isExpanded,
'has-children': hasChildren,
active: isActive
active: isActive(item)
})}
onClick={() => {
if (item.link) {
Expand All @@ -226,7 +235,7 @@ const MenuItem: FC<{
<Icon
name={isExpanded ? 'material-expand_less' : 'material-expand_more'}
size={16}
className='expand-icon'
className={clsx('expand-icon', { active: isActive(item) })}
/>
)}
</div>
Expand Down
1 change: 0 additions & 1 deletion packages/xgen/layouts/wrappers/Chat/Container/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@

.menu-item.expanded .expand-icon {
opacity: 1;
color: var(--color_main);
}

.menu-children {
Expand Down

0 comments on commit de50804

Please sign in to comment.