Skip to content

Commit 92294d1

Browse files
authored
TS Strictmode Textfield and batch of easy components (#3411)
* TS Strictmode for textfield and some easy components
1 parent 10bfa1c commit 92294d1

File tree

14 files changed

+36
-141
lines changed

14 files changed

+36
-141
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"devDependencies": {
5252
"@actions/core": "^1.1.0",
5353
"@actions/github": "^1.1.0",
54-
"@adobe/spectrum-css-workflow-icons": "^1.0.0",
5554
"@babel/cli": "^7.12.10",
5655
"@babel/core": "^7.12.10",
5756
"@babel/node": "^7.12.10",

packages/@react-spectrum/checkbox/src/Checkbox.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ function Checkbox(props: SpectrumCheckboxProps, ref: FocusableRef<HTMLLabelEleme
5151
? useCheckboxGroupItem({
5252
...props,
5353
// Value is optional for standalone checkboxes, but required for CheckboxGroup items;
54-
// it's passed explicitly here to avoid typescript error (requires strictNullChecks disabled).
54+
// it's passed explicitly here to avoid typescript error (requires ignore).
55+
// @ts-ignore
5556
value: props.value,
5657
// Only pass isRequired and validationState to react-aria if they came from
5758
// the props for this individual checkbox, and not from the group via context.

packages/@react-spectrum/checkbox/src/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
import {CheckboxGroupState} from '@react-stately/checkbox';
1414
import React from 'react';
1515

16-
export const CheckboxGroupContext = React.createContext<CheckboxGroupState>(null);
16+
export const CheckboxGroupContext = React.createContext<CheckboxGroupState | null>(null);

packages/@react-spectrum/checkbox/stories/CheckboxGroup.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function render(props: Omit<SpectrumCheckboxGroupProps, 'children'> = {}, checkb
126126
}
127127

128128
function ControlledCheckboxGroup() {
129-
let [checked, setChecked] = useState([]);
129+
let [checked, setChecked] = useState<string[]>([]);
130130
return (
131131
<CheckboxGroup label="Pets" onChange={setChecked} value={checked}>
132132
<Checkbox value="dogs">Dogs</Checkbox>

packages/@react-spectrum/icon/docs/IconTable.tsx

Lines changed: 0 additions & 115 deletions
This file was deleted.

packages/@react-spectrum/icon/docs/workflow-icons.mdx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import workflowIconPackageData from '@spectrum-icons/workflow/package.json';
1717

1818
```jsx import
1919
// import {Icon} from '@react-spectrum/icon';
20-
// import IconTable from './IconTable';
2120
import {Flex} from '@react-spectrum/layout';
2221
```
2322

@@ -96,7 +95,3 @@ import LockClosed from '@spectrum-icons/workflow/LockClosed';
9695

9796
A [searchable list of workflow icons](https://spectrum.adobe.com/page/icons/) is available on the Spectrum website.
9897
The name of the icon without any whitespace matches the import in React Spectrum.
99-
100-
{/* ```tsx snippet
101-
<IconTable iconPackage="workflow" />
102-
``` */}

packages/@react-spectrum/statuslight/chromatic/StatusLight.chromatic.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {StatusLight} from '../';
1717
import {storiesOf} from '@storybook/react';
1818
import {View} from '@react-spectrum/view';
1919

20-
let variants = ['celery', 'yellow', 'fuchsia', 'indigo', 'seafoam', 'chartreuse', 'magenta', 'purple', 'neutral', 'info', 'positive', 'notice', 'negative', 'positive'];
20+
let variants = ['celery', 'yellow', 'fuchsia', 'indigo', 'seafoam', 'chartreuse', 'magenta', 'purple', 'neutral', 'info', 'positive', 'notice', 'negative', 'positive'] as SpectrumStatusLightProps['variant'][];
2121

2222
storiesOf('StatusLight', module)
2323
.add(

packages/@react-spectrum/textfield/src/TextArea.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
*/
1212

1313
import {chain, useLayoutEffect} from '@react-aria/utils';
14-
import React, {RefObject, useCallback, useRef} from 'react';
14+
import React, {Ref, useCallback, useRef} from 'react';
1515
import {SpectrumTextFieldProps, TextFieldRef} from '@react-types/textfield';
1616
import {TextFieldBase} from './TextFieldBase';
1717
import {useControlledState} from '@react-stately/utils';
1818
import {useProviderProps} from '@react-spectrum/provider';
1919
import {useTextField} from '@react-aria/textfield';
2020

21-
function TextArea(props: SpectrumTextFieldProps, ref: RefObject<TextFieldRef>) {
21+
function TextArea(props: SpectrumTextFieldProps, ref: Ref<TextFieldRef>) {
2222
props = useProviderProps(props);
2323
let {
2424
isDisabled = false,
@@ -31,12 +31,12 @@ function TextArea(props: SpectrumTextFieldProps, ref: RefObject<TextFieldRef>) {
3131

3232
// not in stately because this is so we know when to re-measure, which is a spectrum design
3333
let [inputValue, setInputValue] = useControlledState(props.value, props.defaultValue, () => {});
34-
let inputRef = useRef<HTMLTextAreaElement>();
34+
let inputRef = useRef<HTMLTextAreaElement>(null);
3535

3636
let onHeightChange = useCallback(() => {
3737
// Quiet textareas always grow based on their text content.
3838
// Standard textareas also grow by default, unless an explicit height is set.
39-
if (isQuiet || !props.height) {
39+
if ((isQuiet || !props.height) && inputRef.current) {
4040
let input = inputRef.current;
4141
let prevAlignment = input.style.alignSelf;
4242
let prevOverflow = input.style.overflow;

packages/@react-spectrum/textfield/src/TextField.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import React, {forwardRef, RefObject, useRef} from 'react';
13+
import React, {forwardRef, Ref, useRef} from 'react';
1414
import {SpectrumTextFieldProps, TextFieldRef} from '@react-types/textfield';
1515
import {TextFieldBase} from './TextFieldBase';
1616
import {useProviderProps} from '@react-spectrum/provider';
1717
import {useTextField} from '@react-aria/textfield';
1818

19-
function TextField(props: SpectrumTextFieldProps, ref: RefObject<TextFieldRef>) {
19+
function TextField(props: SpectrumTextFieldProps, ref: Ref<TextFieldRef>) {
2020
props = useProviderProps(props);
2121

22-
let inputRef = useRef<HTMLInputElement>();
22+
let inputRef = useRef<HTMLInputElement>(null);
2323
let {labelProps, inputProps, descriptionProps, errorMessageProps} = useTextField(props, inputRef);
2424

2525
if (props.placeholder) {

packages/@react-spectrum/textfield/src/TextFieldBase.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ function TextFieldBase(props: TextFieldBaseProps, ref: Ref<TextFieldRef>) {
5050
inputProps,
5151
descriptionProps,
5252
errorMessageProps,
53-
inputRef,
53+
inputRef: userInputRef,
5454
isLoading,
5555
loadingIndicator,
5656
validationIconClassName
5757
} = props;
5858
let {hoverProps, isHovered} = useHover({isDisabled});
5959
let domRef = useRef<HTMLDivElement>(null);
6060
let defaultInputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null);
61-
inputRef = inputRef || defaultInputRef;
61+
let inputRef = userInputRef || defaultInputRef;
6262

6363
// Expose imperative interface for ref
6464
useImperativeHandle(ref, () => ({

0 commit comments

Comments
 (0)