Skip to content

Commit 3aebd24

Browse files
committed
refactor: SelectPickerTextArea - review fixes, code refactor
1 parent a685205 commit 3aebd24

File tree

4 files changed

+6
-17
lines changed

4 files changed

+6
-17
lines changed

src/Shared/Components/DynamicDataTable/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999

100100
&__indicators {
101101
position: absolute;
102-
top: 8px;
102+
top: 10px;
103103
right: 8px;
104104
}
105105

src/Shared/Components/DynamicDataTable/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export type DynamicDataTableCellPropsMap = {
6363
| 'disableOnBlurResizeToMinHeight'
6464
| 'refVar'
6565
| 'dependentRef'
66+
| 'dependentRefs'
6667
>
6768
[DynamicDataTableRowDataType.DROPDOWN]: Omit<
6869
SelectPickerProps<string, false>,
@@ -80,7 +81,6 @@ export type DynamicDataTableCellPropsMap = {
8081
| 'minHeight'
8182
| 'maxHeight'
8283
| 'refVar'
83-
| 'dependentRef'
8484
| 'dependentRefs'
8585
>
8686
[DynamicDataTableRowDataType.BUTTON]: Pick<

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react'
22
import { InputActionMeta, SelectInstance, SingleValue } from 'react-select'
33

44
import { ReactSelectInputAction } from '@Common/Constants'
5+
import { useThrottledEffect } from '@Common/Helper'
56

67
import SelectPicker from './SelectPicker.component'
78
import { SelectPickerOptionType, SelectPickerTextAreaProps } from './type'
@@ -14,7 +15,6 @@ export const SelectPickerTextArea = ({
1415
minHeight,
1516
maxHeight,
1617
refVar,
17-
dependentRef,
1818
dependentRefs,
1919
...props
2020
}: SelectPickerTextAreaProps) => {
@@ -38,11 +38,6 @@ export const SelectPickerTextArea = ({
3838

3939
// METHODS
4040
const updateDependentRefsHeight = (height: number) => {
41-
const refElement = dependentRef?.current
42-
if (refElement) {
43-
refElement.style.height = `${height}px`
44-
}
45-
4641
Object.values(dependentRefs || {}).forEach((ref) => {
4742
const dependentRefElement = ref?.current
4843
if (dependentRefElement) {
@@ -64,13 +59,6 @@ export const SelectPickerTextArea = ({
6459

6560
let nextHeight = refVar?.current?.scrollHeight || 0
6661

67-
if (dependentRef) {
68-
const refElement = dependentRef.current
69-
if (refElement && refElement.scrollHeight > nextHeight) {
70-
nextHeight = refElement.scrollHeight
71-
}
72-
}
73-
7462
if (dependentRefs) {
7563
Object.values(dependentRefs).forEach((ref) => {
7664
const refElement = ref.current
@@ -91,10 +79,11 @@ export const SelectPickerTextArea = ({
9179
updateRefsHeight(nextHeight)
9280
}
9381

82+
useThrottledEffect(reInitHeight, 500, [inputValue])
83+
9484
const onInputChange = (newValue: string, { action }: InputActionMeta) => {
9585
if (action === ReactSelectInputAction.inputChange) {
9686
setInputValue(newValue)
97-
reInitHeight()
9887

9988
if (!newValue) {
10089
onChange?.(null, {

src/Shared/Components/SelectPicker/type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,4 @@ export type SelectPickerTextAreaProps = Omit<
318318
| 'onCreateOption'
319319
| 'shouldRenderTextArea'
320320
> &
321-
Pick<ResizableTagTextAreaProps, 'maxHeight' | 'minHeight' | 'refVar' | 'dependentRef' | 'dependentRefs'>
321+
Pick<ResizableTagTextAreaProps, 'maxHeight' | 'minHeight' | 'refVar' | 'dependentRefs'>

0 commit comments

Comments
 (0)