Skip to content

Commit 1857d60

Browse files
Shrey DhyaniShrey Dhyani
authored andcommitted
Enhancement: Added enableToggle prop to Close picker on Click. #191
1 parent 53fa472 commit 1857d60

4 files changed

Lines changed: 37 additions & 11 deletions

File tree

apps/storybook/src/stories/molecules/PickerSelectMultiple.stories.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import React from 'react';
2-
import { ComponentStory, ComponentMeta } from '@storybook/react';
31
import { PickerSelectSimple } from '@reusejs/react';
4-
// import { CheckIcon, XIcon } from '@heroicons/react/solid';
5-
// import { TextInputBase } from '@reusejs/react';
2+
import { ComponentMeta, ComponentStory } from '@storybook/react';
3+
import React from 'react';
64

75
const fetchContinents = (q = '') => {
8-
let continents = [
6+
const continents = [
97
'Africa',
108
'Antarctica',
119
'Asia',

apps/storybook/src/stories/molecules/PickerSelectSingle.stories.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1+
import { LabelBase, PickerSelectSimple } from '@reusejs/react';
2+
import { ComponentMeta, ComponentStory } from '@storybook/react';
13
import React, { useState } from 'react';
2-
import { ComponentStory, ComponentMeta } from '@storybook/react';
3-
import { PickerSelectSimple, LabelBase } from '@reusejs/react';
4-
// import { CheckIcon, XIcon } from '@heroicons/react/solid';
5-
// import { TextInputBase } from '@reusejs/react';
64

75
const fetchContinents = (q = '') => {
8-
let continents = [
6+
const continents = [
97
'Africa',
108
'Antarctica',
119
'Asia',
@@ -127,6 +125,23 @@ DisableSearch.args = {
127125
},
128126
};
129127

128+
export const ToggledDisableSearch = Template.bind({});
129+
ToggledDisableSearch.args = {
130+
labelBaseProps: {
131+
label: 'Country',
132+
labelBaseClasses: {
133+
color: 'text-yellow-800 dark:text-yellow-100',
134+
},
135+
},
136+
valueKey: 'value',
137+
multiple: false,
138+
enableSearch: false,
139+
dataSource: (q: any) => {
140+
return fetchContinents(q);
141+
},
142+
enableToggle: true,
143+
};
144+
130145
export const Selected = Template.bind({});
131146
Selected.args = {
132147
labelBaseProps: {

packages/react/src/molecules/pickers/select/base.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface PickerSelectBaseProps {
4949
clearComponent?: any;
5050
noDataComponent?: any;
5151
customRightComponent?: React.FC;
52+
enableToggle?: boolean;
5253
}
5354

5455
const PickerSelectBase = React.forwardRef(
@@ -153,7 +154,13 @@ const PickerSelectBase = React.forwardRef(
153154
)}
154155

155156
{open === true && (
156-
<div className="relative" ref={visRef}>
157+
<div
158+
className="relative"
159+
ref={visRef}
160+
onClick={() => {
161+
props.enableToggle && setOpen(false);
162+
}}
163+
>
157164
{props.searchRenderer && (
158165
<props.searchRenderer
159166
variant={props.variant}

packages/react/src/molecules/pickers/select/simple.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface PickerSelectSimpleProps extends PickerSelectBaseProps {
1010
enableClear: boolean;
1111
enableClose: boolean;
1212
enableSearch: boolean;
13+
enableToggle?: boolean;
1314
}
1415

1516
const PickerSelectSimple = (props: PickerSelectSimpleProps) => {
@@ -47,6 +48,7 @@ const PickerSelectSimple = (props: PickerSelectSimpleProps) => {
4748
refresh={props.refresh}
4849
error={props.error}
4950
customRightComponent={props.customRightComponent}
51+
enableToggle={props.enableToggle}
5052
/>
5153
);
5254
};
@@ -319,4 +321,8 @@ const OptionsRenderer = ({
319321
);
320322
};
321323

324+
PickerSelectSimple.defaultProps = {
325+
enableToggle: false,
326+
};
327+
322328
export default PickerSelectSimple;

0 commit comments

Comments
 (0)