Skip to content

Commit

Permalink
Merge branch 'main' into autoresponder-gpt
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSisb authored Oct 5, 2023
2 parents 4331547 + a684a6b commit 7aed0f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/silver-bottles-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@twilio-paste/data-grid": patch
"@twilio-paste/core": patch
---

chore(data-grid): change isCell function into a type guard and remove unnecessary type assertions
6 changes: 3 additions & 3 deletions packages/paste-core/components/data-grid/src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ export const DataGrid = React.forwardRef<HTMLTableElement, DataGridProps>(
// Set the actionable state
setActionable(true);

const activeElement = getActiveElement() as HTMLElement;
const activeElement = getActiveElement();
// Only if it's a DataGrid cell
if (isCell(activeElement)) {
if (activeElement && isCell(activeElement)) {
// Get the first focusable child
const firstFocusableElement = getFirstFocusableIn(activeElement);

// If there is a focusable child focus it
if (firstFocusableElement) {
ensureFocus(firstFocusableElement as HTMLElement);
ensureFocus(firstFocusableElement);
// First shift+tab fix upon entering actionable mode
activeElement.tabIndex = actionable ? 0 : -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const delayedSetFocusable = (element?: HTMLElement): void => {
*
* @returns {boolean}.
*/
export const isCell = (element: Element): boolean => {
export const isCell = (element: Element): element is HTMLTableCellElement => {
return element.tagName === "TD" || element.tagName === "TH";
};

Expand Down Expand Up @@ -73,7 +73,7 @@ export const getClosestGridCellFromCurrentFocus = (dataGridId: string): HTMLElem
return null;
}
if (isCell(focusedElement)) {
return focusedElement as HTMLElement;
return focusedElement;
}
return getClosestCellFrom(focusedElement, dataGridId);
};

0 comments on commit 7aed0f0

Please sign in to comment.