Skip to content

Commit fc45733

Browse files
authored
TS strict aria hooks batch (#5069)
* TS strict aria hooks batch
1 parent 05ded40 commit fc45733

32 files changed

+266
-170
lines changed

packages/@react-aria/focus/docs/FocusScope.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ to move focus to the next and previous elements.
5252
To get a focus manager, call the <TypeLink links={docs.links} type={docs.exports.useFocusManager} /> hook
5353
from a component within the FocusScope. A focus manager supports the following methods:
5454

55-
<ClassAPI links={docs.links} class={docs.links[docs.exports.useFocusManager.return.id]} />
55+
<ClassAPI links={docs.links} class={docs.links[docs.exports.FocusManager.id]} />
5656

5757
## Example
5858

packages/@react-aria/focus/src/FocusScope.tsx

Lines changed: 129 additions & 85 deletions
Large diffs are not rendered by default.

packages/@react-aria/focus/src/isElementVisible.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function isStyleVisible(element: Element) {
2424
);
2525

2626
if (isVisible) {
27-
const {getComputedStyle} = element.ownerDocument.defaultView;
27+
const {getComputedStyle} = element.ownerDocument.defaultView as unknown as Window;
2828
let {display: computedDisplay, visibility: computedVisibility} = getComputedStyle(element);
2929

3030
isVisible = (
@@ -49,11 +49,11 @@ function isAttributeVisible(element: Element, childElement?: Element) {
4949
}
5050

5151
/**
52-
* Adapted from https://github.com/testing-library/jest-dom and
52+
* Adapted from https://github.com/testing-library/jest-dom and
5353
* https://github.com/vuejs/vue-test-utils-next/.
5454
* Licensed under the MIT License.
5555
* @param element - Element to evaluate for display or visibility.
56-
*/
56+
*/
5757
export function isElementVisible(element: Element, childElement?: Element) {
5858
return (
5959
element.nodeName !== '#comment' &&

packages/@react-aria/focus/src/useFocusable.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
import {DOMAttributes, FocusableDOMProps, FocusableElement, FocusableProps} from '@react-types/shared';
1414
import {focusSafely} from './';
15-
import {mergeProps, useSyncRef} from '@react-aria/utils';
16-
import React, {MutableRefObject, ReactNode, RefObject, useContext, useEffect, useRef} from 'react';
15+
import {mergeProps, useObjectRef, useSyncRef} from '@react-aria/utils';
16+
import React, {ForwardedRef, MutableRefObject, ReactNode, RefObject, useContext, useEffect, useRef} from 'react';
1717
import {useFocus, useKeyboard} from '@react-aria/interactions';
1818

1919
export interface FocusableOptions extends FocusableProps, FocusableDOMProps {
@@ -30,7 +30,7 @@ interface FocusableContextValue extends FocusableProviderProps {
3030
ref?: MutableRefObject<FocusableElement>
3131
}
3232

33-
let FocusableContext = React.createContext<FocusableContextValue>(null);
33+
let FocusableContext = React.createContext<FocusableContextValue | null>(null);
3434

3535
function useFocusableContext(ref: RefObject<FocusableElement>): FocusableContextValue {
3636
let context = useContext(FocusableContext) || {};
@@ -44,11 +44,12 @@ function useFocusableContext(ref: RefObject<FocusableElement>): FocusableContext
4444
/**
4545
* Provides DOM props to the nearest focusable child.
4646
*/
47-
function FocusableProvider(props: FocusableProviderProps, ref: RefObject<FocusableElement>) {
47+
function FocusableProvider(props: FocusableProviderProps, ref: ForwardedRef<FocusableElement>) {
4848
let {children, ...otherProps} = props;
49+
let objRef = useObjectRef(ref);
4950
let context = {
5051
...otherProps,
51-
ref
52+
ref: objRef
5253
};
5354

5455
return (

packages/@react-aria/focus/stories/FocusScope.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function MaybePortal({children, isPortaled}: {children: ReactNode, isPortaled: b
4343

4444
return ReactDOM.createPortal(
4545
<>{children}</>,
46-
document.getElementById(dialogsRoot)
46+
document.getElementById(dialogsRoot)!
4747
);
4848
}
4949

@@ -135,7 +135,7 @@ function FocusableFirstInScopeExample() {
135135
</>
136136
);
137137
}
138-
const contents = [];
138+
const contents: React.JSX.Element[] = [];
139139
for (let i = 0; i < 3; i++) {
140140
contents.push(DialogContent(i));
141141
}

packages/@react-aria/i18n/src/context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface I18nProviderProps {
2121
locale?: string
2222
}
2323

24-
const I18nContext = React.createContext<Locale>(null);
24+
const I18nContext = React.createContext<Locale | null>(null);
2525

2626
/**
2727
* Provides the locale for the application to all child components.

packages/@react-aria/i18n/src/useCollator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function useCollator(options?: Intl.CollatorOptions): Intl.Collator {
2424

2525
let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');
2626
if (cache.has(cacheKey)) {
27-
return cache.get(cacheKey);
27+
return cache.get(cacheKey)!;
2828
}
2929

3030
let formatter = new Intl.Collator(locale, options);

packages/@react-aria/i18n/src/useDateFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface DateFormatterOptions extends Intl.DateTimeFormatOptions {
2626
*/
2727
export function useDateFormatter(options?: DateFormatterOptions): DateFormatter {
2828
// Reuse last options object if it is shallowly equal, which allows the useMemo result to also be reused.
29-
options = useDeepMemo(options, isEqual);
29+
options = useDeepMemo(options ?? {}, isEqual);
3030
let {locale} = useLocale();
3131
return useMemo(() => new DateFormatter(locale, options), [locale, options]);
3232
}

packages/@react-aria/i18n/src/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export function isRTL(locale: string) {
2424
if (Intl.Locale) {
2525
// @ts-ignore
2626
let script = new Intl.Locale(locale).maximize().script;
27+
if (!script) {
28+
return false;
29+
}
2730
return RTL_SCRIPTS.has(script);
2831
}
2932

packages/@react-aria/interactions/src/DOMPropsContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface IDOMPropsResponderContext extends DOMAttributes {
2323
ref?: MutableRefObject<Element>
2424
}
2525

26-
export const DOMPropsResponderContext = React.createContext<IDOMPropsResponderContext>(null);
26+
export const DOMPropsResponderContext = React.createContext<IDOMPropsResponderContext | null>(null);
2727

2828
export function useDOMPropsResponderContext(props: DOMPropsResponderProps): DOMPropsResponderProps {
2929
// Consume context from <DOMPropsResponder> and merge with props.

0 commit comments

Comments
 (0)