Skip to content

Commit 418abed

Browse files
committed
feat(rangeselect): add customizable input placeholders
1 parent 7d289d1 commit 418abed

3 files changed

Lines changed: 26 additions & 18 deletions

File tree

src/components/RangeSelect/RangeSelect.stories.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export default {
77
component: RangeSelect,
88
argTypes: {
99
placeholder: { control: { type: 'text' } },
10+
rangeFromLabel: { control: { type: 'text' } },
11+
rangeToLabel: { control: { type: 'text' } },
12+
rangeFromPlaceholder: { control: { type: 'text' } },
13+
rangeToPlaceholder: { control: { type: 'text' } },
1014
isDisabled: { control: { type: 'boolean' } },
1115
isInvalid: { control: { type: 'boolean' } },
1216
isFullWidth: { control: { type: 'boolean' } },
@@ -37,11 +41,7 @@ export default {
3741
const Template: StoryFn<typeof RangeSelect> = (args) => <RangeSelect {...args} />;
3842

3943
export const Default = Template.bind({});
40-
Default.args = {
41-
placeholder: 'Select a range',
42-
rangeFromLabel: 'From',
43-
rangeToLabel: 'To',
44-
};
44+
Default.args = {};
4545

4646
export const WithValidation: StoryFn<typeof RangeSelect> = (args) => {
4747
const [value, setValue] = useState<string[]>(['', '']);

src/components/RangeSelect/RangeSelect.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ describe('The RangeSelect component', () => {
99
expect(screen.getByText('Select a range')).toBeInTheDocument();
1010
});
1111

12-
it('opens dropdown and shows From/To labels when clicked', async () => {
13-
render(<RangeSelect />);
12+
it('opens dropdown and shows From/To labels and placeholders when clicked', async () => {
13+
render(<RangeSelect rangeFromPlaceholder="10" rangeToPlaceholder="20" />);
1414

1515
const combobox = screen.getByRole('combobox');
1616
await act(async () => {
@@ -20,6 +20,8 @@ describe('The RangeSelect component', () => {
2020
await waitFor(() => {
2121
expect(screen.getByText('From')).toBeInTheDocument();
2222
expect(screen.getByText('To')).toBeInTheDocument();
23+
expect(screen.getByPlaceholderText('10')).toBeInTheDocument();
24+
expect(screen.getByPlaceholderText('20')).toBeInTheDocument();
2325
});
2426
});
2527

src/components/RangeSelect/RangeSelect.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ export interface RangeSelectProps
1212
color?: string;
1313
clearText?: string;
1414
placeholder?: string;
15-
isDisabled?: boolean;
16-
isInvalid?: boolean;
17-
isFullWidth?: boolean;
1815
rangeFromLabel?: string;
1916
rangeToLabel?: string;
17+
rangeFromPlaceholder?: string;
18+
rangeToPlaceholder?: string;
2019
rangeFromError?: string;
2120
rangeToError?: string;
21+
isDisabled?: boolean;
22+
isInvalid?: boolean;
23+
isFullWidth?: boolean;
2224
value?: string[];
2325
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
2426
dropdownWidth?: '3xs' | '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
@@ -28,22 +30,24 @@ export interface RangeSelectProps
2830
}
2931

3032
export const RangeSelect: React.FC<RangeSelectProps> = ({
33+
variant = 'outline',
34+
borderColor = selectRecipe.variants?.visual[variant]?.borderColor,
35+
backgroundColor = selectRecipe.variants?.visual[variant]?.backgroundColor,
3136
color = 'black',
32-
placeholder = 'Select a range',
3337
clearText = 'Clear',
34-
isDisabled = false,
35-
isInvalid = false,
36-
isFullWidth = true,
38+
placeholder = 'Select a range',
3739
rangeFromLabel = 'From',
3840
rangeToLabel = 'To',
41+
rangeFromPlaceholder: fromPlaceholder = '',
42+
rangeToPlaceholder: toPlaceholder = '',
3943
rangeFromError,
4044
rangeToError,
45+
isDisabled = false,
46+
isInvalid = false,
47+
isFullWidth = true,
48+
value,
4149
size = 'md',
4250
dropdownWidth,
43-
variant = 'outline',
44-
borderColor = selectRecipe.variants?.visual[variant]?.borderColor,
45-
backgroundColor = selectRecipe.variants?.visual[variant]?.backgroundColor,
46-
value,
4751
onChange,
4852
onClose,
4953
...rest
@@ -191,6 +195,7 @@ export const RangeSelect: React.FC<RangeSelectProps> = ({
191195
<Input
192196
type="number"
193197
size="md"
198+
placeholder={fromPlaceholder}
194199
value={selectedOptions[0] || ''}
195200
onChange={(e) => handleRangeChange(0, e.target.value)}
196201
borderRadius="md"
@@ -216,6 +221,7 @@ export const RangeSelect: React.FC<RangeSelectProps> = ({
216221
</Text>
217222
<Input
218223
type="number"
224+
placeholder={toPlaceholder}
219225
size="md"
220226
value={selectedOptions[1] || ''}
221227
onChange={(e) => handleRangeChange(1, e.target.value)}

0 commit comments

Comments
 (0)