Skip to content

Commit

Permalink
fix(Select): #413 (#414)
Browse files Browse the repository at this point in the history
* fix(Select): #413

* fix: Revert update by prettier.
  • Loading branch information
yoshi6jp authored Sep 15, 2023
1 parent c122bea commit 4f4dd09
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
44 changes: 42 additions & 2 deletions src/Select/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { render, screen } from '@testing-library/react'
import Select from './index'
import userEvent from '@testing-library/user-event'
import { SelectProps } from './Select'
import { ComponentColor, ComponentSize } from '../types';
import Checkbox from '../Checkbox';
import { ComponentColor, ComponentSize } from '../types'
import Checkbox from '../Checkbox'

const TestComponent = (props?: Omit<SelectProps, 'children'>) => {
return (
Expand Down Expand Up @@ -170,4 +170,44 @@ describe('Select', () => {
render(<TestComponent className={testClass} />)
expect(screen.getByRole('combobox')).toHaveClass(testClass)
})
it('Should render single item', () => {
render(
<Select>
<Select.Option value="" disabled>
Single Item
</Select.Option>
</Select>
)
})
it('#413', () => {
const options = [
{
label: 'a',
value: 'a',
disabled: false,
},
{
label: 'b',
value: 'b',
disabled: false,
},
{
label: 'c',
value: 'c',
disabled: false,
},
]
render(
<Select>
<Select.Option value="" disabled>
Select Item
</Select.Option>
{options.map((o) => (
<Select.Option key={o.label} value={o.value} disabled={o.disabled}>
{o.label}
</Select.Option>
))}
</Select>
)
})
})
9 changes: 7 additions & 2 deletions src/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import React, { ReactElement } from 'react'
import clsx from 'clsx'
import { twMerge } from 'tailwind-merge'

import { IComponentBaseProps, ComponentColor, ComponentSize } from '../types'
import {
IComponentBaseProps,
ComponentColor,
ComponentSize,
ListOrItem,
} from '../types'

import SelectOption, { SelectOptionProps } from './SelectOption'

Expand All @@ -11,7 +16,7 @@ export type SelectProps = Omit<
'size' | 'color'
> &
IComponentBaseProps & {
children: ReactElement<SelectOptionProps>[]
children: ListOrItem<ReactElement<SelectOptionProps>>
size?: ComponentSize
color?: ComponentColor
bordered?: boolean
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ export type ComponentSize = typeof componentSizes[number]
export type ComponentStatus = typeof componentStatuses[number]
export type ComponentBrandColors = typeof brandColors[number]
export type ComponentBgColors = typeof bgColors[number]

export type ListOrItem<T> = T[] | T | Array<T | T[]>

0 comments on commit 4f4dd09

Please sign in to comment.