From 1c1e2e3b2792577392fceced08dd1c4597cd347a Mon Sep 17 00:00:00 2001 From: Jungzl <13jungzl@gmail.com> Date: Sun, 26 Mar 2023 11:39:45 +0800 Subject: [PATCH] fix(Field): label-align top works well with label-width (#11684) * fix(Field): label-align top works well with label-width * fix(Field): update snapshot * fix(Field): break long label when `labelAlign="top"` --- packages/vant-cli/src/cli.ts | 4 ++ packages/vant-cli/src/commands/jest.ts | 1 + packages/vant/package.json | 1 + packages/vant/src/field/Field.tsx | 15 ++++- packages/vant/src/field/demo/LabelAlign.vue | 34 +++++++++-- packages/vant/src/field/index.less | 13 ++-- .../test/__snapshots__/demo.spec.ts.snap | 61 ++++++++++++++++++- .../test/__snapshots__/props.spec.tsx.snap | 19 ++++++ packages/vant/src/form/test/props.spec.tsx | 1 + 9 files changed, 131 insertions(+), 18 deletions(-) diff --git a/packages/vant-cli/src/cli.ts b/packages/vant-cli/src/cli.ts index bdefe31bf..d2d866de0 100644 --- a/packages/vant-cli/src/cli.ts +++ b/packages/vant-cli/src/cli.ts @@ -45,6 +45,10 @@ program '--runInBand', 'Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests' ) + .option( + '--updateSnapshot', + 'Re-record every snapshot that fails during this test run' + ) .option('--debug', 'Print debugging info about your Jest config') .action(async (options) => { const { test } = await import('./commands/jest.js'); diff --git a/packages/vant-cli/src/commands/jest.ts b/packages/vant-cli/src/commands/jest.ts index 284a95c44..1ba81287b 100644 --- a/packages/vant-cli/src/commands/jest.ts +++ b/packages/vant-cli/src/commands/jest.ts @@ -24,6 +24,7 @@ export function test(command: Config.Argv) { clearCache: command.clearCache, changedSince: command.changedSince, logHeapUsage: command.logHeapUsage, + updateSnapshot: command.updateSnapshot, // make jest tests faster // see: https://ivantanev.com/make-jest-faster/ maxWorkers: '50%', diff --git a/packages/vant/package.json b/packages/vant/package.json index 6e0c3f264..5292dbdf4 100644 --- a/packages/vant/package.json +++ b/packages/vant/package.json @@ -20,6 +20,7 @@ "build:site": "vant-cli build-site", "release": "cp ../../README.md ./ && vant-cli release && rm ./README.md", "release:site": "pnpm build:site && npx gh-pages -d site-dist --add", + "test:update": "vant-cli test --updateSnapshot", "test:watch": "vant-cli test --watch", "test:coverage": "open test/coverage/index.html" }, diff --git a/packages/vant/src/field/Field.tsx b/packages/vant/src/field/Field.tsx index d6c1341b0..e1b7f977a 100644 --- a/packages/vant/src/field/Field.tsx +++ b/packages/vant/src/field/Field.tsx @@ -434,7 +434,8 @@ export default defineComponent({ const labelStyle = computed(() => { const labelWidth = getProp('labelWidth'); - if (labelWidth) { + const labelAlign = getProp('labelAlign'); + if (labelWidth && labelAlign !== 'top') { return { width: addUnit(labelWidth) }; } }); @@ -571,6 +572,8 @@ export default defineComponent({ }; const renderLabel = () => { + const labelWidth = getProp('labelWidth'); + const labelAlign = getProp('labelAlign'); const colon = getProp('colon') ? ':' : ''; if (slots.label) { @@ -578,7 +581,15 @@ export default defineComponent({ } if (props.label) { return ( -