diff --git a/package.json b/package.json index 44e80d6..297ad44 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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" }, diff --git a/src/Inputs/useDynamicInputs.ts b/src/Inputs/useDynamicInputs.ts index 173447e..2ca32dc 100644 --- a/src/Inputs/useDynamicInputs.ts +++ b/src/Inputs/useDynamicInputs.ts @@ -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> { diff --git a/src/useInertiaForm.ts b/src/useInertiaForm.ts index c38173b..4e991fd 100644 --- a/src/useInertiaForm.ts +++ b/src/useInertiaForm.ts @@ -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" diff --git a/src/utils/fillEmptyValues.ts b/src/utils/fillEmptyValues.ts index 45bdcdf..63821b4 100644 --- a/src/utils/fillEmptyValues.ts +++ b/src/utils/fillEmptyValues.ts @@ -1,4 +1,4 @@ -import { isPlainObject } from "lodash" +import { isPlainObject } from "es-toolkit" /** * Replaces undefined or null values with empty values, diff --git a/src/utils/isUnset.ts b/src/utils/isUnset.ts index 9eb1ca2..3a177ec 100644 --- a/src/utils/isUnset.ts +++ b/src/utils/isUnset.ts @@ -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 diff --git a/src/utils/renameObjectWithAttributes.ts b/src/utils/renameObjectWithAttributes.ts index c5fd393..ee037c4 100644 --- a/src/utils/renameObjectWithAttributes.ts +++ b/src/utils/renameObjectWithAttributes.ts @@ -1,4 +1,4 @@ -import { isPlainObject } from "lodash" +import { isPlainObject } from "es-toolkit" import { NestedObject } from "../useInertiaForm" /** diff --git a/src/utils/unsetCompact.ts b/src/utils/unsetCompact.ts index e4b1b32..c30a68a 100644 --- a/src/utils/unsetCompact.ts +++ b/src/utils/unsetCompact.ts @@ -1,4 +1,4 @@ -import { unset, get } from "lodash" +import { unset, get } from "es-toolkit/compat" import { type NestedObject } from "../useInertiaForm" /** diff --git a/tests/useInertiaInput.test.tsx b/tests/useInertiaInput.test.tsx index 6f475dd..eb80cbf 100644 --- a/tests/useInertiaInput.test.tsx +++ b/tests/useInertiaInput.test.tsx @@ -66,4 +66,38 @@ describe ("useInertiaInput", () => { }) }) + + describe("Text input value changes", () => { + it("maintains empty value when all characters are deleted", () => { + render( +
+ +
, + ) + + 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("") + }) + }) }) diff --git a/yarn.lock b/yarn.lock index de59820..9a1e719 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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" @@ -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