Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/components/select.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Select as AntSelect, type SelectProps as AntSelectProps } from 'antd';

import { cn } from '../lib';

/**
* The shared select entry point. It deliberately keeps Ant Design's option
* model intact while making sizing, invalid state and the stable ui-select
* hook part of the product contract.
*/
export interface SelectProps<ValueType = unknown> extends AntSelectProps<ValueType> {
invalid?: boolean;
}

export function Select<ValueType = unknown>({
className,
invalid,
status,
'aria-invalid': ariaInvalid,
...props
}: SelectProps<ValueType>) {
return (
<AntSelect<ValueType>
className={cn('ui-select', className)}
status={invalid ? 'error' : status}
aria-invalid={(ariaInvalid ?? invalid) || undefined}
{...props}
/>
);
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export {
DropdownMenuTrigger,
} from './components/dropdown-menu';
export { Input, type InputProps } from './components/input';
export { Select, type SelectProps } from './components/select';
export { Skeleton } from './components/skeleton';
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './components/tooltip';
export { AppShell, type AppShellProps } from './patterns/app-shell';
Expand Down
4 changes: 4 additions & 0 deletions src/styles/components.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
width: 100%;
}

.ui-select.ant-select {
width: 100%;
}

.ui-card__header {
display: flex;
flex-direction: column;
Expand Down
15 changes: 15 additions & 0 deletions tests/primitives.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
DropdownMenuItem,
DropdownMenuTrigger,
Input,
Select,
Skeleton,
Tooltip,
TooltipContent,
Expand Down Expand Up @@ -46,6 +47,20 @@ describe('core primitives', () => {
);
});

it('renders the shared select with a stable hook and invalid state', () => {
render(
<Select
aria-label="Workspace scope"
invalid
value="project"
options={[{ value: 'project', label: 'Project' }]}
/>,
);
const select = screen.getByRole('combobox', { name: 'Workspace scope' });
expect(select.closest('.ui-select')).toBeInTheDocument();
expect(select).toHaveAttribute('aria-invalid', 'true');
});

it('forwards a native input ref for focus, selection and DOM listeners', () => {
const ref = createRef<HTMLInputElement>();
const { unmount } = render(
Expand Down
Loading