-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Typecasting
forwardRef
inside Select (#1774)
- Loading branch information
1 parent
0ccd7b7
commit 70428a9
Showing
9 changed files
with
217 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@itwin/itwinui-react': patch | ||
--- | ||
|
||
Fixed `Select` and `LabeledSelect` to correctly handle generic types. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/itwinui-react/src/core/LabeledSelect/LabeledSelect.types-test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
/** | ||
* This test file tests some LabeledSelect type related cases that have not been tested in other files | ||
* (e.g. react-workshop, unit tests, etc.) | ||
*/ | ||
|
||
import React, { useRef } from 'react'; | ||
import LabeledSelect from './LabeledSelect.js'; | ||
|
||
() => { | ||
const ref = useRef(null); | ||
return ( | ||
<> | ||
<LabeledSelect | ||
options={[ | ||
{ value: 1, label: 'Option 1' }, | ||
{ value: 2, label: 'Option 2' }, | ||
{ value: 3, label: 'Option 3' }, | ||
]} | ||
onChange={(value) => { | ||
const returnValue: number = value; | ||
return returnValue; | ||
}} | ||
ref={ref} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
() => { | ||
return ( | ||
<> | ||
<LabeledSelect<number> | ||
options={[ | ||
{ value: 1, label: 'Option 1' }, | ||
{ value: 2, label: 'Option 2' }, | ||
{ value: 3, label: 'Option 3' }, | ||
]} | ||
onChange={(value) => { | ||
const returnValue: number = value; | ||
return returnValue; | ||
}} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
() => { | ||
return ( | ||
<> | ||
<LabeledSelect<string> | ||
label='Select Label' | ||
options={[ | ||
{ value: '1', label: 'Item #1' }, | ||
{ value: '2', label: 'Item #2' }, | ||
{ value: '3', label: 'Item #3' }, | ||
]} | ||
onChange={(value) => { | ||
const returnValue: string = value; | ||
return returnValue; | ||
}} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
() => { | ||
return ( | ||
<> | ||
<LabeledSelect<string> | ||
label='Select Label' | ||
options={[ | ||
// There should be error: TS 2322 | ||
// @ts-expect-error (TS 2322): Type 'number' is not assignable to type 'string'. | ||
{ value: 1, label: 'Item #1' }, | ||
]} | ||
onChange={(value) => { | ||
const returnValue: string = value; | ||
return returnValue; | ||
}} | ||
/> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
packages/itwinui-react/src/core/Select/Select.types-test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
/** | ||
* This test file tests some Select type related cases that have not been tested in other files | ||
* (e.g. react-workshop, unit tests, etc.) | ||
*/ | ||
|
||
import React, { useRef } from 'react'; | ||
import Select from './Select.js'; | ||
|
||
() => { | ||
const ref = useRef(null); | ||
return ( | ||
<> | ||
<Select | ||
options={[ | ||
{ value: 1, label: 'Option 1' }, | ||
{ value: 2, label: 'Option 2' }, | ||
{ value: 3, label: 'Option 3' }, | ||
]} | ||
onChange={(value) => { | ||
const returnValue: number = value; | ||
return returnValue; | ||
}} | ||
ref={ref} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
() => { | ||
return ( | ||
<> | ||
<Select<number> | ||
options={[ | ||
{ value: 1, label: 'Option 1' }, | ||
{ value: 2, label: 'Option 2' }, | ||
{ value: 3, label: 'Option 3' }, | ||
]} | ||
onChange={(value) => { | ||
const returnValue: number = value; | ||
return returnValue; | ||
}} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
() => { | ||
return ( | ||
<> | ||
<Select<string> | ||
options={[ | ||
{ value: '1', label: 'Option 1' }, | ||
{ value: '2', label: 'Option 2' }, | ||
{ value: '3', label: 'Option 3' }, | ||
]} | ||
onChange={(value) => { | ||
const returnValue: string = value; | ||
return returnValue; | ||
}} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
() => { | ||
return ( | ||
<> | ||
<Select<string> | ||
label='Select Label' | ||
options={[ | ||
// There should be error: TS 2322 | ||
// @ts-expect-error (TS 2322): Type 'number' is not assignable to type 'string'. | ||
{ value: 1, label: 'Item #1' }, | ||
]} | ||
onChange={(value) => { | ||
const returnValue: string = value; | ||
return returnValue; | ||
}} | ||
/> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
// TODO: Test all the files, and not just the Table files or just the build files. | ||
"include": ["src/core/Table/**/*", "src/react-table/*"] | ||
"include": [ | ||
"src/core/Table/**/*", | ||
"src/react-table/*", | ||
"src/core/Select/**/*", | ||
"src/core/LabeledSelect/**/*" | ||
] | ||
} |