Update DashboardTabs for Improved ID Handling and Scrolling Logic
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 `htmlId` prop to `DashboardTabItem` for better accessibility and unique identification of tab items. - Adjusted scrolling logic to account for offset, enhancing the user experience when navigating through tabs.
This commit is contained in:
parent
b54669fd26
commit
4c1766044f
@ -77,6 +77,7 @@ DashboardTabLabel.propTypes = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const DashboardTabItem = memo(function DashboardTabItem({
|
const DashboardTabItem = memo(function DashboardTabItem({
|
||||||
|
htmlId = undefined,
|
||||||
tab,
|
tab,
|
||||||
tabIndex,
|
tabIndex,
|
||||||
isSelected,
|
isSelected,
|
||||||
@ -142,7 +143,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}`}
|
id={htmlId}
|
||||||
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)}
|
||||||
@ -190,6 +191,7 @@ const DashboardTabItem = memo(function DashboardTabItem({
|
|||||||
DashboardTabItem.displayName = 'DashboardTabItem'
|
DashboardTabItem.displayName = 'DashboardTabItem'
|
||||||
|
|
||||||
DashboardTabItem.propTypes = {
|
DashboardTabItem.propTypes = {
|
||||||
|
htmlId: PropTypes.string,
|
||||||
tab: PropTypes.shape({
|
tab: PropTypes.shape({
|
||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string.isRequired,
|
||||||
title: PropTypes.string,
|
title: PropTypes.string,
|
||||||
@ -749,13 +751,13 @@ const DashboardTabs = () => {
|
|||||||
|
|
||||||
const offset = 50
|
const offset = 50
|
||||||
|
|
||||||
// Tab is off-screen to the left
|
// Tab is too close to / off-screen on the left
|
||||||
if (tabItemRect.left < scrollRect.left) {
|
if (tabItemRect.left < scrollRect.left + offset) {
|
||||||
scrollEl.scrollLeft -= scrollRect.left - tabItemRect.left + offset
|
scrollEl.scrollLeft -= scrollRect.left - tabItemRect.left + offset
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tab is off-screen to the right
|
// Tab is too close to / off-screen on the right
|
||||||
else if (tabItemRect.right > scrollRect.right) {
|
else if (tabItemRect.right > scrollRect.right - offset) {
|
||||||
scrollEl.scrollLeft += tabItemRect.right - scrollRect.right + offset
|
scrollEl.scrollLeft += tabItemRect.right - scrollRect.right + offset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -816,6 +818,7 @@ const DashboardTabs = () => {
|
|||||||
tabIndex={index}
|
tabIndex={index}
|
||||||
isSelected={isSelected}
|
isSelected={isSelected}
|
||||||
isDragging={isDragging}
|
isDragging={isDragging}
|
||||||
|
htmlId={`dashboard-tab-item-${tab.id}`}
|
||||||
dropPosition={
|
dropPosition={
|
||||||
isDropTarget
|
isDropTarget
|
||||||
? dropTarget.insertBefore
|
? dropTarget.insertBefore
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user