-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Select): option and optgroup compond components
- Loading branch information
1 parent
ab65142
commit c406f4d
Showing
11 changed files
with
118 additions
and
61 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
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
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
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
20 changes: 20 additions & 0 deletions
20
packages/react/src/components/form/Select/SelectOptgroup.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,20 @@ | ||
import { Slot } from '@radix-ui/react-slot'; | ||
import { forwardRef } from 'react'; | ||
import type { OptgroupHTMLAttributes } from 'react'; | ||
|
||
export type SelectOptgroupProps = { | ||
/** | ||
* Change the default rendered element for the one passed as a child, merging their props and behavior. | ||
* @default false | ||
*/ | ||
asChild?: boolean; | ||
} & OptgroupHTMLAttributes<HTMLOptGroupElement>; | ||
|
||
export const SelectOptgroup = forwardRef< | ||
HTMLOptGroupElement, | ||
SelectOptgroupProps | ||
>(function SelectOptgroup({ asChild, ...rest }, ref) { | ||
const Component = asChild ? Slot : 'optgroup'; | ||
|
||
return <Component {...rest} ref={ref} />; | ||
}); |
19 changes: 19 additions & 0 deletions
19
packages/react/src/components/form/Select/SelectOption.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,19 @@ | ||
import { Slot } from '@radix-ui/react-slot'; | ||
import { forwardRef } from 'react'; | ||
import type { OptionHTMLAttributes } from 'react'; | ||
|
||
export type SelectOptionProps = { | ||
/** | ||
* Change the default rendered element for the one passed as a child, merging their props and behavior. | ||
* @default false | ||
*/ | ||
asChild?: boolean; | ||
} & OptionHTMLAttributes<HTMLOptionElement>; | ||
|
||
export const SelectOption = forwardRef<HTMLOptionElement, SelectOptionProps>( | ||
function SelectOption({ asChild, ...rest }, ref) { | ||
const Component = asChild ? Slot : 'option'; | ||
|
||
return <Component {...rest} ref={ref} />; | ||
}, | ||
); |
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,2 +1,21 @@ | ||
export { Select } from './Select'; | ||
import { Select as SelectParent } from './Select'; | ||
import { SelectOptgroup } from './SelectOptgroup'; | ||
import { SelectOption } from './SelectOption'; | ||
|
||
type SelectComponent = typeof SelectParent & { | ||
Option: typeof SelectOption; | ||
Optgroup: typeof SelectOptgroup; | ||
}; | ||
|
||
const Select = SelectParent as SelectComponent; | ||
|
||
Select.Option = SelectOption; | ||
Select.Optgroup = SelectOptgroup; | ||
|
||
Select.Option.displayName = 'Select.Option'; | ||
Select.Optgroup.displayName = 'Select.Optgroup'; | ||
|
||
export type { SelectProps } from './Select'; | ||
export type { SelectOptionProps } from './SelectOption'; | ||
export type { SelectOptgroupProps } from './SelectOptgroup'; | ||
export { Select, SelectOption, SelectOptgroup }; |
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