Skip to content

Commit 8e5804e

Browse files
authored
fix: Convert 'select" element to 'input' element (#148)
* fix overflowing text * Use convert select element to an input-dropdown * Use 100% width for dropdown options * revert changelog changes
1 parent eb5f184 commit 8e5804e

File tree

3 files changed

+64
-12
lines changed

3 files changed

+64
-12
lines changed

src/ui/components/inputField/InputDropdown.tsx

+38-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* License for the specific language governing permissions and limitations
1313
* under the License.
1414
*/
15-
import React, { useCallback, useState } from "react";
15+
import React, { useCallback, useRef, useState } from "react";
1616
import { getImageUrl } from "../../../utils";
1717
import TooltipContainer from "../tooltip/tooltip";
1818

@@ -48,6 +48,8 @@ const InputDropdown: React.FC<InputDropdownPropTypes> = (props) => {
4848
const [isFocused, setIsFocused] = useState<boolean>(false);
4949
const [isTouched, setIsTouched] = useState(false);
5050

51+
const inputRef = useRef<HTMLInputElement>(null);
52+
5153
const onChange = useCallback(
5254
(
5355
event:
@@ -64,7 +66,13 @@ const InputDropdown: React.FC<InputDropdownPropTypes> = (props) => {
6466
const showError = props.error && (isTouched || props.forceShowError);
6567

6668
return (
67-
<div className="input-field-container">
69+
<div
70+
className="input-field-container"
71+
onBlur={() => {
72+
setTimeout(() => {
73+
setIsFocused(false);
74+
}, 100);
75+
}}>
6876
{props.label && (
6977
<label
7078
htmlFor={props.name}
@@ -86,26 +94,44 @@ const InputDropdown: React.FC<InputDropdownPropTypes> = (props) => {
8694
{props.prefix}
8795
</div>
8896
)}
89-
<select
97+
<input
9098
name={props.name}
9199
id={props.name + "-text"}
92100
onChange={onChange}
93101
value={props.value}
94102
autoFocus={props.autofocus}
95103
onFocus={() => setIsFocused(true)}
96-
onBlur={() => setIsFocused(false)}
97-
className={`text-small text-black input-field ${showError ? "input-field-error-state" : ""} ${
98-
props.size === "small" ? "input-field-small" : ""
99-
}`}>
104+
onBlur={() => {
105+
setTimeout(() => setIsFocused(false), 200);
106+
}}
107+
className={`input-dropdown text-small text-black input-field ${
108+
showError ? "input-field-error-state" : ""
109+
} ${props.size === "small" ? "input-field-small" : ""}`}
110+
type="text"
111+
ref={inputRef}
112+
/>
113+
</div>
114+
{isFocused && (
115+
<div className="input-dropdown-options">
100116
{props.options.map((option, index) => (
101-
<option
117+
<div
102118
key={index}
103-
value={option}>
119+
className="input-dropdown-option"
120+
onClick={() => {
121+
if (inputRef.current) {
122+
const syntheticChangeEvent = new Event("change", { bubbles: true });
123+
Object.defineProperty(syntheticChangeEvent, "target", {
124+
value: { value: option, name: props.name },
125+
writable: true,
126+
});
127+
onChange(syntheticChangeEvent as unknown as React.ChangeEvent<HTMLInputElement>);
128+
}
129+
}}>
104130
{option}
105-
</option>
131+
</div>
106132
))}
107-
</select>
108-
</div>
133+
</div>
134+
)}
109135
{showError && errorPlacement === "bottom" && (
110136
<div className="input-field-error block-small block-error">
111137
<img

src/ui/components/inputField/InputField.css

+23
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,26 @@ textarea.input-field {
130130
top: 20%;
131131
left: -24px;
132132
}
133+
134+
.input-dropdown-options {
135+
position: absolute;
136+
width: 100%;
137+
display: flex;
138+
flex-direction: column;
139+
top: 44px;
140+
left: 0;
141+
z-index: 1000;
142+
border-radius: 6px;
143+
border: none;
144+
outline: none;
145+
background-color: white;
146+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
147+
}
148+
.input-dropdown-option {
149+
padding: 12px 15px 12px;
150+
cursor: pointer;
151+
font-size: 13px;
152+
}
153+
.input-dropdown-option:hover {
154+
background-color: var(--color-input-field-prefix-bg);
155+
}

src/ui/components/userDetail/userDetailForm.scss

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
span {
4343
color: #ed344e;
4444
font-weight: bold;
45+
word-break: break-all;
46+
hyphens: auto;
47+
overflow-wrap: anywhere;
4548
}
4649
}
4750
}

0 commit comments

Comments
 (0)