Merged in fix/3697-prettier-configs (pull request #3396)
fix(SW-3691): Setup one prettier config for whole repo * Setup prettierrc in root and remove other configs Approved-by: Joakim Jäderberg Approved-by: Linus Flood
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { ChangeEvent, ChangeEventHandler, RefObject } from 'react'
|
||||
import { useState, useEffect } from 'react'
|
||||
import type { ChangeEvent, ChangeEventHandler, RefObject } from "react"
|
||||
import { useState, useEffect } from "react"
|
||||
|
||||
interface ClearInputOptions {
|
||||
inputRef: RefObject<HTMLInputElement | null>
|
||||
@@ -26,7 +26,7 @@ export function clearInput({
|
||||
if (isControlled && onChange) {
|
||||
// For controlled components: call onChange with a synthetic event
|
||||
const syntheticEvent = {
|
||||
target: { value: '' },
|
||||
target: { value: "" },
|
||||
currentTarget: inputRef.current,
|
||||
} as ChangeEvent<HTMLInputElement>
|
||||
onChange(syntheticEvent)
|
||||
@@ -35,24 +35,24 @@ export function clearInput({
|
||||
// This triggers React's change detection properly
|
||||
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
|
||||
window.HTMLInputElement.prototype,
|
||||
'value'
|
||||
"value"
|
||||
)?.set
|
||||
|
||||
if (nativeInputValueSetter) {
|
||||
nativeInputValueSetter.call(inputRef.current, '')
|
||||
nativeInputValueSetter.call(inputRef.current, "")
|
||||
} else {
|
||||
inputRef.current.value = ''
|
||||
inputRef.current.value = ""
|
||||
}
|
||||
|
||||
// Dispatch input event to trigger any listeners
|
||||
const inputEvent = new Event('input', {
|
||||
const inputEvent = new Event("input", {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
})
|
||||
inputRef.current.dispatchEvent(inputEvent)
|
||||
|
||||
// Also dispatch change event
|
||||
const changeEvent = new Event('change', {
|
||||
const changeEvent = new Event("change", {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
})
|
||||
@@ -74,16 +74,16 @@ export function useInputHasValue(
|
||||
const [hasValue, setHasValue] = useState(() => {
|
||||
// For controlled components, check value prop
|
||||
if (value !== undefined) {
|
||||
return String(value ?? '').trim().length > 0
|
||||
return String(value ?? "").trim().length > 0
|
||||
}
|
||||
// For uncontrolled, check ref
|
||||
return String(inputRef.current?.value ?? '').trim().length > 0
|
||||
return String(inputRef.current?.value ?? "").trim().length > 0
|
||||
})
|
||||
|
||||
// Sync with controlled value changes
|
||||
useEffect(() => {
|
||||
if (value !== undefined) {
|
||||
setHasValue(String(value ?? '').trim().length > 0)
|
||||
setHasValue(String(value ?? "").trim().length > 0)
|
||||
}
|
||||
}, [value])
|
||||
|
||||
@@ -102,17 +102,17 @@ export function useInputHasValue(
|
||||
setTimeout(() => {
|
||||
const target = (event?.target as HTMLInputElement) || inputRef.current
|
||||
if (target) {
|
||||
setHasValue((target.value ?? '').trim().length > 0)
|
||||
setHasValue((target.value ?? "").trim().length > 0)
|
||||
}
|
||||
}, 0)
|
||||
}
|
||||
|
||||
input.addEventListener('input', updateHasValue)
|
||||
input.addEventListener("input", updateHasValue)
|
||||
// Also listen to change event as a fallback
|
||||
input.addEventListener('change', updateHasValue)
|
||||
input.addEventListener("change", updateHasValue)
|
||||
return () => {
|
||||
input.removeEventListener('input', updateHasValue)
|
||||
input.removeEventListener('change', updateHasValue)
|
||||
input.removeEventListener("input", updateHasValue)
|
||||
input.removeEventListener("change", updateHasValue)
|
||||
}
|
||||
}, [value, inputRef])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user