GeezerVison is showing github.com — [react-interactions] Refine a11y component flow types (#17032) · react/react@55731fd
File treeExpand file treeCollapse file tree Open diff view settings packages/react-interactions/accessibility/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-interactions/accessibility/src/FocusContain.js +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,12 +30,12 @@ export default function FocusContain({ | 30 | 30 | children, | 31 | 31 | disabled, | 32 | 32 | tabScope: TabScope, | 33 | | -}: FocusContainProps) { | | 33 | +}: FocusContainProps): React.Node { | 34 | 34 | const scopeRef = useRef(null); | 35 | 35 | // This ensures tabbing works through the React tree (including Portals and Suspense nodes) | 36 | 36 | const keyboard = useKeyboard({ | 37 | 37 | onKeyDown(event: KeyboardEvent): void { | 38 | | - if (disabled || event.key !== 'Tab') { | | 38 | + if (disabled === true || event.key !== 'Tab') { | 39 | 39 | event.continuePropagation(); | 40 | 40 | return; | 41 | 41 | } | @@ -51,7 +51,7 @@ export default function FocusContain({ | 51 | 51 | }); | 52 | 52 | const focusWithin = useFocusWithin({ | 53 | 53 | onBlurWithin: function(event) { | 54 | | - if (disabled) { | | 54 | + if (disabled === true) { | 55 | 55 | event.continuePropagation(); | 56 | 56 | return; | 57 | 57 | } | @@ -66,7 +66,7 @@ export default function FocusContain({ | 66 | 66 | useLayoutEffect( | 67 | 67 | () => { | 68 | 68 | const scope = scopeRef.current; | 69 | | - if (scope && !disabled) { | | 69 | + if (scope !== null && disabled !== true) { | 70 | 70 | const elems = scope.getScopedNodes(); | 71 | 71 | if (elems && elems.indexOf(document.activeElement) === -1) { | 72 | 72 | elems[0].focus(); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-interactions/accessibility/src/FocusGroup.js +5-3Lines changed: 5 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -90,7 +90,9 @@ function hasModifierKey(event: KeyboardEvent): boolean { | 90 | 90 | ); | 91 | 91 | } | 92 | 92 |
| 93 | | -export function createFocusGroup(scope: ReactScope): Array<React.Component> { | | 93 | +export function createFocusGroup( | | 94 | + scope: ReactScope, | | 95 | +): [(FocusGroupProps) => React.Node, (FocusItemProps) => React.Node] { | 94 | 96 | const TableScope = React.unstable_createScope(scope.fn); | 95 | 97 |
| 96 | 98 | function Group({ | @@ -99,7 +101,7 @@ export function createFocusGroup(scope: ReactScope): Array<React.Component> { | 99 | 101 | wrap, | 100 | 102 | tabScope: TabScope, | 101 | 103 | allowModifiers, | 102 | | - }): FocusGroupProps { | | 104 | + }: FocusGroupProps): React.Node { | 103 | 105 | const tabScopeRef = useRef(null); | 104 | 106 | return ( | 105 | 107 | <TableScope | @@ -117,7 +119,7 @@ export function createFocusGroup(scope: ReactScope): Array<React.Component> { | 117 | 119 | ); | 118 | 120 | } | 119 | 121 |
| 120 | | - function Item({children, onKeyDown}): FocusItemProps { | | 122 | + function Item({children, onKeyDown}: FocusItemProps): React.Node { | 121 | 123 | const scopeRef = useRef(null); | 122 | 124 | const keyboard = useKeyboard({ | 123 | 125 | onKeyDown(event: KeyboardEvent): void { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-interactions/accessibility/src/FocusManager.js +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,16 +41,16 @@ export function focusNext( | 41 | 41 | event.continuePropagation(); | 42 | 42 | } | 43 | 43 | } else if (focusedElement === lastTabbableElem) { | 44 | | - if (contain) { | | 44 | + if (contain === true) { | 45 | 45 | focusElem(firstTabbableElem); | 46 | 46 | if (event) { | 47 | 47 | event.preventDefault(); | 48 | 48 | } | 49 | 49 | } else if (event) { | 50 | 50 | event.continuePropagation(); | 51 | 51 | } | 52 | | - } else { | 53 | | - focusElem((tabbableNodes: any)[currentIndex + 1]); | | 52 | + } else if (tabbableNodes) { | | 53 | + focusElem(tabbableNodes[currentIndex + 1]); | 54 | 54 | if (event) { | 55 | 55 | event.preventDefault(); | 56 | 56 | } | @@ -75,16 +75,16 @@ export function focusPrevious( | 75 | 75 | event.continuePropagation(); | 76 | 76 | } | 77 | 77 | } else if (focusedElement === firstTabbableElem) { | 78 | | - if (contain) { | | 78 | + if (contain === true) { | 79 | 79 | focusElem(lastTabbableElem); | 80 | 80 | if (event) { | 81 | 81 | event.preventDefault(); | 82 | 82 | } | 83 | 83 | } else if (event) { | 84 | 84 | event.continuePropagation(); | 85 | 85 | } | 86 | | - } else { | 87 | | - focusElem((tabbableNodes: any)[currentIndex - 1]); | | 86 | + } else if (tabbableNodes) { | | 87 | + focusElem(tabbableNodes[currentIndex - 1]); | 88 | 88 | if (event) { | 89 | 89 | event.preventDefault(); | 90 | 90 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-interactions/accessibility/src/FocusTable.js +10-26Lines changed: 10 additions & 26 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,28 +38,6 @@ type FocusTableProps = {| | 38 | 38 |
| 39 | 39 | const {useRef} = React; | 40 | 40 |
| 41 | | -export function focusFirstCellOnTable(table: ReactScopeMethods): void { | 42 | | - const rows = table.getChildren(); | 43 | | - if (rows !== null) { | 44 | | - const firstRow = rows[0]; | 45 | | - if (firstRow !== null) { | 46 | | - const cells = firstRow.getChildren(); | 47 | | - if (cells !== null) { | 48 | | - const firstCell = cells[0]; | 49 | | - if (firstCell !== null) { | 50 | | - const tabbableNodes = firstCell.getScopedNodes(); | 51 | | - if (tabbableNodes !== null) { | 52 | | - const firstElem = tabbableNodes[0]; | 53 | | - if (firstElem !== null) { | 54 | | - firstElem.focus(); | 55 | | - } | 56 | | - } | 57 | | - } | 58 | | - } | 59 | | - } | 60 | | - } | 61 | | -} | 62 | | - | 63 | 41 | function focusScope(cell: ReactScopeMethods, event?: KeyboardEvent): void { | 64 | 42 | const tabbableNodes = cell.getScopedNodes(); | 65 | 43 | if (tabbableNodes !== null && tabbableNodes.length > 0) { | @@ -178,7 +156,13 @@ function hasModifierKey(event: KeyboardEvent): boolean { | 178 | 156 | ); | 179 | 157 | } | 180 | 158 |
| 181 | | -export function createFocusTable(scope: ReactScope): Array<React.Component> { | | 159 | +export function createFocusTable( | | 160 | + scope: ReactScope, | | 161 | +): [ | | 162 | + (FocusTableProps) => React.Node, | | 163 | + (FocusRowProps) => React.Node, | | 164 | + (FocusCellProps) => React.Node, | | 165 | +] { | 182 | 166 | const TableScope = React.unstable_createScope(scope.fn); | 183 | 167 |
| 184 | 168 | function Table({ | @@ -188,7 +172,7 @@ export function createFocusTable(scope: ReactScope): Array<React.Component> { | 188 | 172 | wrapY, | 189 | 173 | tabScope: TabScope, | 190 | 174 | allowModifiers, | 191 | | - }): FocusTableProps { | | 175 | + }: FocusTableProps): React.Node { | 192 | 176 | const tabScopeRef = useRef(null); | 193 | 177 | return ( | 194 | 178 | <TableScope | @@ -207,11 +191,11 @@ export function createFocusTable(scope: ReactScope): Array<React.Component> { | 207 | 191 | ); | 208 | 192 | } | 209 | 193 |
| 210 | | - function Row({children}): FocusRowProps { | | 194 | + function Row({children}: FocusRowProps): React.Node { | 211 | 195 | return <TableScope type="row">{children}</TableScope>; | 212 | 196 | } | 213 | 197 |
| 214 | | - function Cell({children, onKeyDown, colSpan}): FocusCellProps { | | 198 | + function Cell({children, onKeyDown, colSpan}: FocusCellProps): React.Node { | 215 | 199 | const scopeRef = useRef(null); | 216 | 200 | const keyboard = useKeyboard({ | 217 | 201 | onKeyDown(event: KeyboardEvent): void { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-interactions/accessibility/src/shared/getTabbableNodes.js +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 |
| 10 | 10 | import type {ReactScopeMethods} from 'shared/ReactTypes'; | 11 | 11 |
| 12 | | -export default function getTabbableNodes(scope: ReactScopeMethods) { | | 12 | +export default function getTabbableNodes( | | 13 | + scope: ReactScopeMethods, | | 14 | +): [ | | 15 | + null | Array<HTMLElement>, | | 16 | + null | HTMLElement, | | 17 | + null | HTMLElement, | | 18 | + number, | | 19 | + null | HTMLElement, | | 20 | +] { | 13 | 21 | const tabbableNodes = scope.getScopedNodes(); | 14 | 22 | if (tabbableNodes === null || tabbableNodes.length === 0) { | 15 | 23 | return [null, null, null, 0, null]; | |
|