Enhance DashboardTabs Interaction and Scrolling Behavior
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good
- Added unique IDs to dashboard tab items for improved accessibility and interaction. - Implemented handleSelectTab function to manage tab selection and ensure proper scrolling behavior when tabs are selected, enhancing user experience.
This commit is contained in:
parent
396327f6ef
commit
b54669fd26
@ -142,6 +142,7 @@ const DashboardTabItem = memo(function DashboardTabItem({
|
|||||||
draggable
|
draggable
|
||||||
onDragStart={(event) => onDragStart(event, tab.id)}
|
onDragStart={(event) => onDragStart(event, tab.id)}
|
||||||
onDragEnd={onDragEnd}
|
onDragEnd={onDragEnd}
|
||||||
|
id={`dashboard-tab-item-${tab.id}`}
|
||||||
onClick={() => onClick(tab.id)}
|
onClick={() => onClick(tab.id)}
|
||||||
onKeyDown={(event) => onKeyDown(event, tabIndex)}
|
onKeyDown={(event) => onKeyDown(event, tabIndex)}
|
||||||
onDragOver={(event) => onDragOver(event, tab)}
|
onDragOver={(event) => onDragOver(event, tab)}
|
||||||
@ -730,10 +731,39 @@ const DashboardTabs = () => {
|
|||||||
? tabs.findIndex((tab) => tab.id === activeTabId)
|
? tabs.findIndex((tab) => tab.id === activeTabId)
|
||||||
: 0
|
: 0
|
||||||
|
|
||||||
|
const handleSelectTab = (tabId) => {
|
||||||
|
selectTab(tabId)
|
||||||
|
|
||||||
|
const scrollEl = rootRef.current?.querySelector(
|
||||||
|
'.simplebar-content-wrapper'
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!scrollEl) return
|
||||||
|
|
||||||
|
const tabItem = document.getElementById(`dashboard-tab-item-${tabId}`)
|
||||||
|
|
||||||
|
if (!tabItem) return
|
||||||
|
|
||||||
|
const tabItemRect = tabItem.getBoundingClientRect()
|
||||||
|
const scrollRect = scrollEl.getBoundingClientRect()
|
||||||
|
|
||||||
|
const offset = 50
|
||||||
|
|
||||||
|
// Tab is off-screen to the left
|
||||||
|
if (tabItemRect.left < scrollRect.left) {
|
||||||
|
scrollEl.scrollLeft -= scrollRect.left - tabItemRect.left + offset
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tab is off-screen to the right
|
||||||
|
else if (tabItemRect.right > scrollRect.right) {
|
||||||
|
scrollEl.scrollLeft += tabItemRect.right - scrollRect.right + offset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const tabItemProps = {
|
const tabItemProps = {
|
||||||
onDragStart: handleItemDragStart,
|
onDragStart: handleItemDragStart,
|
||||||
onDragEnd: handleItemDragEnd,
|
onDragEnd: handleItemDragEnd,
|
||||||
onClick: selectTab,
|
onClick: handleSelectTab,
|
||||||
onKeyDown: handleKeyDown,
|
onKeyDown: handleKeyDown,
|
||||||
onDragOver: handleItemDragOver,
|
onDragOver: handleItemDragOver,
|
||||||
onDrop: handleItemDrop,
|
onDrop: handleItemDrop,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user