@uniai-fe/uds-primitives 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -275,8 +275,7 @@ const Text = forwardRef<HTMLInputElement, InputProps>(
|
|
|
275
275
|
[onChange, registerOnChange],
|
|
276
276
|
);
|
|
277
277
|
|
|
278
|
-
const
|
|
279
|
-
event.preventDefault();
|
|
278
|
+
const dispatchNativeInputEvent = useCallback(() => {
|
|
280
279
|
const inputEl = inputRef.current;
|
|
281
280
|
if (!inputEl) {
|
|
282
281
|
return;
|
|
@@ -288,11 +287,25 @@ const Text = forwardRef<HTMLInputElement, InputProps>(
|
|
|
288
287
|
nativeSetter?.call(inputEl, "");
|
|
289
288
|
const changeEvent = new Event("input", { bubbles: true });
|
|
290
289
|
inputEl.dispatchEvent(changeEvent);
|
|
291
|
-
setHasValue(false);
|
|
292
|
-
setIsClearInteracting(false);
|
|
293
|
-
inputEl.focus();
|
|
294
290
|
}, []);
|
|
295
291
|
|
|
292
|
+
const handleClear = useCallback(
|
|
293
|
+
(event: MouseEvent<HTMLButtonElement>) => {
|
|
294
|
+
event.preventDefault();
|
|
295
|
+
dispatchNativeInputEvent();
|
|
296
|
+
setHasValue(false);
|
|
297
|
+
setIsClearInteracting(false);
|
|
298
|
+
const inputEl = inputRef.current;
|
|
299
|
+
inputEl?.focus();
|
|
300
|
+
// 일부 브라우저(특히 로그인 필드)가 focus 직후 자동완성을 재삽입하는 경우가 있어
|
|
301
|
+
// 다음 프레임에서 한 번 더 초기화해 값을 비워 둔다.
|
|
302
|
+
requestAnimationFrame(() => {
|
|
303
|
+
dispatchNativeInputEvent();
|
|
304
|
+
});
|
|
305
|
+
},
|
|
306
|
+
[dispatchNativeInputEvent],
|
|
307
|
+
);
|
|
308
|
+
|
|
296
309
|
const handleClearPointerDown = useCallback(() => {
|
|
297
310
|
setIsClearInteracting(true);
|
|
298
311
|
}, []);
|