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
2 changes: 0 additions & 2 deletions src/components/Select/Select.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

user-select: none;
width: 100%;
min-height: var(--min-height);
padding: calc(0.5rem - var(--border-width)) calc(0.75rem - var(--border-width));

&[data-clearable="true"] {
border-top-right-radius: 0;
Expand Down
11 changes: 11 additions & 0 deletions src/components/Select/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ const meta: Meta<typeof Select> = {
table: { category: 'Behavior' },
},
onChange: { table: { disable: true } },
size: {
control: 'select',
options: ['small', 'normal', 'large'],
description: 'The size of the select.',
table: { category: 'Appearance' },
},
value: { table: { disable: true } },
},
};
Expand All @@ -38,6 +44,7 @@ export const Text: Story = {
name: 'Text',
args: {
disabled: false,
size: 'normal',
options: [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' },
Expand All @@ -53,6 +60,7 @@ export const Numeric: Story = {
name: 'Numeric',
args: {
disabled: false,
size: 'normal',
options: [
{ value: 1, label: 'Critical' },
{ value: 2, label: 'High' },
Expand All @@ -68,6 +76,7 @@ export const CustomItemComponents: Story = {
name: 'Custom Item Components',
args: {
disabled: false,
size: 'normal',
options: [
{
value: '7b90a423-1979-4e61-a30b-b19d663b3e43',
Expand All @@ -94,6 +103,7 @@ export const ControlledValue: Story = {
},
args: {
disabled: false,
size: 'normal',
options: [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' },
Expand All @@ -109,6 +119,7 @@ export const ManyItems: Story = {
name: 'Many (200+) Items',
args: {
disabled: false,
size: 'normal',
options: Array.from({ length: 200 }, (_, i) => ({
value: i + 1,
label: `Item ${i + 1}`,
Expand Down
11 changes: 10 additions & 1 deletion src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ChevronUp,
} from 'lucide-react';

import { ElementSize } from '../../types';
import { getStyleClassNames, sx } from '../../utils/getStyleClassNames';

import styles from './Select.module.scss';
Expand All @@ -34,6 +35,7 @@ export interface SelectProps extends Omit<
'multiple' |
'onChange' |
'placeholder' |
'size' |
'value'
> {
defaultValue?: SelectValue | null;
Expand All @@ -42,6 +44,7 @@ export interface SelectProps extends Omit<
onChange?: (value: SelectValue | null) => void;
options: SelectOption[];
placeholder?: ReactNode;
size?: ElementSize;
value?: SelectValue | null;
}

Expand All @@ -58,6 +61,7 @@ export const Select = forwardRef<SelectRef, SelectProps>(({
placeholder = 'Select...',
readOnly,
required,
size = 'normal',
type: _type,
value,
...triggerProps
Expand All @@ -82,11 +86,16 @@ export const Select = forwardRef<SelectRef, SelectProps>(({
intent: 'secondary',
variant: 'ghost',
border: true,
size,
}), className)}
>
<BaseSelect.Value>
{(val: SelectValue | null) => {
const opt = options.find((o) => o.value === val) ?? null;

/* BaseUI may pass undefined instead of null when the selected value is null, so use loose
* equality for null-valued options to match both.
*/
const opt = options.find((o) => (o.value === null ? val == null : o.value === val)) ?? null;
if (opt === null) {
return placeholder;
}
Expand Down
4 changes: 3 additions & 1 deletion src/style/sizes.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
box-sizing: border-box;
min-width: $size;
min-height: $size;
padding: calc(#{$padding} - var(--border-width)); // Assume always used with variants (1px border, even if invisible)

// Assume always used with variants (1px border, even if invisible)
padding: calc(#{$padding} - var(--border-width)) calc(#{$padding} + 0.125rem - var(--border-width));

&.collapse-padding {
margin: 0 calc($padding * -1);
Expand Down
Loading