Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"circular-json": "^0.5.9",
"commitizen": "^4.3.1",
"cz-conventional-changelog": "^3.3.0",
"es-toolkit": "^1.33.0",
"eslint": "^9.17.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-import-resolver-typescript": "^3.7.0",
Expand All @@ -96,7 +97,6 @@
"jest-fixed-jsdom": "^0.0.9",
"jest-mock-axios": "^4.8.0",
"lint-staged": "^15.3.0",
"lodash": "^4.17.21",
"msw": "^2.7.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
Expand All @@ -117,7 +117,6 @@
"peerDependencies": {
"@inertiajs/react": "^1.0.0 || ^2.0.0",
"axios": "^1.7.8",
"lodash": "^2.0.0 || ^3.0.0 || ^4.0.0",
"react": "^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
"react-dom": "^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Inputs/useDynamicInputs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback } from "react"
import { useForm, useFormMeta } from "../Form"
import { get, set } from "lodash"
import { get, set } from "es-toolkit/compat"
import { useNestedAttribute } from "./NestedFields"

export interface DynamicInputsProps<T = Record<string, unknown>> {
Expand All @@ -24,7 +24,7 @@
try {
const nestedModel = useNestedAttribute()
inputModel = formModel ? `${inputModel}.${nestedModel}` : nestedModel
} catch(e) {}

Check warning on line 27 in src/Inputs/useDynamicInputs.ts

View workflow job for this annotation

GitHub Actions / test

'e' is defined but never used

inputModel = `${inputModel}.${model || ""}`

Expand All @@ -50,13 +50,13 @@

return clone
})
}, [])

Check warning on line 53 in src/Inputs/useDynamicInputs.ts

View workflow job for this annotation

GitHub Actions / test

React Hook useCallback has missing dependencies: 'emptyData', 'inputModel', and 'setData'. Either include them or remove the dependency array

const handleRemoveInputs = useCallback((i: number) => {
const record = getData(`${inputModel}[${i}]`) as T
unsetData(`${inputModel}[${i}]`)
return record
}, [])

Check warning on line 59 in src/Inputs/useDynamicInputs.ts

View workflow job for this annotation

GitHub Actions / test

React Hook useCallback has missing dependencies: 'getData', 'inputModel', and 'unsetData'. Either include them or remove the dependency array

const data = getData(inputModel)

Expand All @@ -64,7 +64,7 @@
if(!Array.isArray(data)) return []

return data.map((_, i) => `${model || ""}[${i}]`)
}, [data])

Check warning on line 67 in src/Inputs/useDynamicInputs.ts

View workflow job for this annotation

GitHub Actions / test

React Hook useCallback has a missing dependency: 'model'. Either include it or remove the dependency array

return {
addInput: handleAddInputs,
Expand Down
3 changes: 2 additions & 1 deletion src/useInertiaForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
type Path,
type PathValue,
} from "./utils"
import { get, isEqual, isPlainObject, set } from "lodash"
import { isEqual, isPlainObject } from "es-toolkit"
import { get, set } from "es-toolkit/compat"
import { useFormMeta } from "./Form/FormMetaWrapper"
import axios, { AxiosResponse } from "axios"

Expand Down
2 changes: 1 addition & 1 deletion src/utils/fillEmptyValues.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isPlainObject } from "lodash"
import { isPlainObject } from "es-toolkit"

/**
* Replaces undefined or null values with empty values,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/isUnset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isEmpty } from "lodash"
import { isEmpty } from "es-toolkit/compat"

/**
* Returns whether a value should be considered empty in the context of a form input
Expand Down
2 changes: 1 addition & 1 deletion src/utils/renameObjectWithAttributes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isPlainObject } from "lodash"
import { isPlainObject } from "es-toolkit"
import { NestedObject } from "../useInertiaForm"

/**
Expand Down
2 changes: 1 addition & 1 deletion src/utils/unsetCompact.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unset, get } from "lodash"
import { unset, get } from "es-toolkit/compat"
import { type NestedObject } from "../useInertiaForm"

/**
Expand Down
34 changes: 34 additions & 0 deletions tests/useInertiaInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,38 @@ describe ("useInertiaInput", () => {
})

})

describe("Text input value changes", () => {
it("maintains empty value when all characters are deleted", () => {
render(
<Form role="form" to="/" model="values" data={ { values: { name: "initial" } } } remember={ false }>
<Input role="input" name="name" />
</Form>,
)

const input = screen.getByRole("input")

// Initial state
expect(input).toHaveValue("initial")

// Delete some characters (backspace)
fireEvent.input(input, { target: { value: "init" } })
expect(input).toHaveValue("init")

// Delete all characters (backspace)
fireEvent.input(input, { target: { value: "" } })
expect(input).toHaveValue("")

// Delete all characters (select all + delete)
fireEvent.input(input, { target: { value: "" } })
expect(input).toHaveValue("")

// Try setting to undefined
fireEvent.input(input, { target: { value: undefined } })
expect(input).toHaveValue("")

// Verify value stays empty
expect(input).toHaveValue("")
})
})
})
15 changes: 13 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6025,6 +6025,18 @@ __metadata:
languageName: node
linkType: hard

"es-toolkit@npm:^1.33.0":
version: 1.33.0
resolution: "es-toolkit@npm:1.33.0"
dependenciesMeta:
"@trivago/prettier-plugin-sort-imports@4.3.0":
unplugged: true
prettier-plugin-sort-re-exports@0.0.1:
unplugged: true
checksum: 10/db613d885c407dc3b84b3939b8b0c9976f658bfb03fa0f9cd3a3fe8383a60a75e1e4f34584e86c3fbf00def50ea0ca5f1a5264a1014018286dedbed08426b5f0
languageName: node
linkType: hard

"escalade@npm:^3.1.1, escalade@npm:^3.2.0":
version: 3.2.0
resolution: "escalade@npm:3.2.0"
Expand Down Expand Up @@ -13816,6 +13828,7 @@ __metadata:
circular-json: "npm:^0.5.9"
commitizen: "npm:^4.3.1"
cz-conventional-changelog: "npm:^3.3.0"
es-toolkit: "npm:^1.33.0"
eslint: "npm:^9.17.0"
eslint-config-airbnb-typescript: "npm:^18.0.0"
eslint-import-resolver-typescript: "npm:^3.7.0"
Expand All @@ -13833,7 +13846,6 @@ __metadata:
jest-fixed-jsdom: "npm:^0.0.9"
jest-mock-axios: "npm:^4.8.0"
lint-staged: "npm:^15.3.0"
lodash: "npm:^4.17.21"
msw: "npm:^2.7.0"
react: "npm:^19.0.0"
react-dom: "npm:^19.0.0"
Expand All @@ -13853,7 +13865,6 @@ __metadata:
peerDependencies:
"@inertiajs/react": ^1.0.0 || ^2.0.0
axios: ^1.7.8
lodash: ^2.0.0 || ^3.0.0 || ^4.0.0
react: ^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
react-dom: ^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
languageName: unknown
Expand Down
Loading