-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix cellClassRule type, fix keyboard timeout, small refactoring #123
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { | |
KEYDOWN_EVENT, | ||
KEYUP_EVENT, | ||
MULTIPLE_KEY_PRESS_CHANGED, | ||
SCROLLING, | ||
} from '../../constants/eventsConstants'; | ||
import { | ||
findGridRootFromCurrent, | ||
|
@@ -45,6 +46,7 @@ const getNextCellIndexes = (code: string, indexes: CellIndexCoordinates) => { | |
export const useKeyboard = (options: GridOptions, initialised: boolean, apiRef: ApiRef): void => { | ||
const logger = useLogger('useKeyboard'); | ||
const isMultipleKeyPressed = React.useRef(false); | ||
const rafFocusOnCellRef = React.useRef(0); | ||
|
||
const onMultipleKeyChange = React.useCallback( | ||
(isPressed: boolean) => { | ||
|
@@ -106,19 +108,29 @@ export const useKeyboard = (options: GridOptions, initialised: boolean, apiRef: | |
nextCellIndexes.colIndex = | ||
nextCellIndexes.colIndex >= colCount ? colCount - 1 : nextCellIndexes.colIndex; | ||
|
||
apiRef.current!.scrollToIndexes(nextCellIndexes); | ||
setTimeout(() => { | ||
const nextCell = getCellElementFromIndexes(root, nextCellIndexes); | ||
if (rafFocusOnCellRef.current) { | ||
cancelAnimationFrame(rafFocusOnCellRef.current); | ||
} | ||
|
||
if (nextCell) { | ||
nextCell.tabIndex = 0; | ||
(nextCell as HTMLDivElement).focus(); | ||
} | ||
}, 100); | ||
apiRef.current!.once(SCROLLING, () => { | ||
rafFocusOnCellRef.current = requestAnimationFrame(() => { | ||
const nextCell = getCellElementFromIndexes(root, nextCellIndexes); | ||
|
||
if (nextCell) { | ||
logger.debug( | ||
`Focusing on cell with index ${nextCellIndexes.rowIndex} - ${nextCellIndexes.colIndex} `, | ||
); | ||
nextCell.tabIndex = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we change the tabIndex for the next cell at the same time we change it for the previous cell? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at this stage the previous cell is already changed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, for a short moment, we have all the cells with tabIndex={-1}, none with tabIndex={0}. I was wondering if it's important. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes that's correct. I don't think it is 🤔 |
||
(nextCell as HTMLDivElement).focus(); | ||
} | ||
}); | ||
}); | ||
|
||
apiRef.current!.scrollToIndexes(nextCellIndexes); | ||
|
||
return nextCellIndexes; | ||
}, | ||
[apiRef, options.pagination, options.pageSize], | ||
[apiRef, options.pagination, options.pageSize, logger], | ||
); | ||
|
||
const selectActiveRow = React.useCallback(() => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ | |
.unknown { | ||
background: coral; | ||
} | ||
.border { | ||
border: 1px solid orangered; | ||
} | ||
#root { | ||
top:0; | ||
left: 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to follow, why is moving the focus conditional to the grid scrolling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because the dom element of the new cell might not be there yet.