Skip to content

Commit a41f46b

Browse files
committed
feat: update version to 1.23.5-beta-2 and enhance SelectPickerTextArea with input dirty state management
1 parent f995984 commit a41f46b

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.23.5-beta-1",
3+
"version": "1.23.5-beta-2",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Shared/Components/SelectPicker/SelectPickerTextArea.component.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ export const SelectPickerTextArea = ({
3232
maxHeight,
3333
refVar,
3434
dependentRefs,
35+
filterOption: filterOptionProp,
3536
...props
3637
}: SelectPickerTextAreaProps) => {
3738
// STATES
3839
const [inputValue, setInputValue] = useState((value as SingleValue<SelectPickerOptionType<string>>)?.value || '')
40+
const [isInputDirty, setIsInputDirty] = useState(false)
3941

4042
// REFS
4143
const selectRef = useRef<SelectInstance<SelectPickerOptionType<string>>>(null)
@@ -50,6 +52,7 @@ export const SelectPickerTextArea = ({
5052
useEffect(() => {
5153
const selectValue = value as SingleValue<SelectPickerOptionType<string>>
5254
setInputValue(selectValue?.value || '')
55+
setIsInputDirty(false)
5356
}, [value])
5457

5558
// METHODS
@@ -120,9 +123,23 @@ export const SelectPickerTextArea = ({
120123
return false
121124
}
122125

126+
const filterOption: SelectPickerTextAreaProps['filterOption'] = (...filterOptionArgs) => {
127+
if (!isInputDirty) {
128+
return true
129+
}
130+
131+
if (filterOptionProp) {
132+
return filterOptionProp(...filterOptionArgs)
133+
}
134+
135+
const [option, rawInput] = filterOptionArgs
136+
return option.label.toLowerCase().includes(rawInput.toLowerCase())
137+
}
138+
123139
const onInputChange = (newValue: string, { action }: InputActionMeta) => {
124140
if (action === ReactSelectInputAction.inputChange) {
125141
setInputValue(newValue)
142+
setIsInputDirty(true)
126143

127144
if (!newValue) {
128145
onChange?.(null, {
@@ -137,6 +154,7 @@ export const SelectPickerTextArea = ({
137154
const selectValue = value as SingleValue<SelectPickerOptionType<string>>
138155
// Reverting input to previously selected value in case of blur event. (no-selection)
139156
setInputValue(selectValue?.value || '')
157+
setIsInputDirty(false)
140158
}
141159
}
142160

@@ -195,6 +213,7 @@ export const SelectPickerTextArea = ({
195213
selectRef={selectRef}
196214
inputValue={inputValue}
197215
value={value}
216+
filterOption={filterOption}
198217
onInputChange={onInputChange}
199218
controlShouldRenderValue={false}
200219
onChange={onChange}

0 commit comments

Comments
 (0)