diff --git a/src/field/Field.tsx b/src/field/Field.tsx index 75f0cd386..38112ce66 100644 --- a/src/field/Field.tsx +++ b/src/field/Field.tsx @@ -567,11 +567,13 @@ export default defineComponent({ center={props.center} border={props.border} isLink={props.isLink} - required={props.required} clickable={props.clickable} titleStyle={labelStyle.value} valueClass={bem('value')} - titleClass={[bem('label', labelAlign), props.labelClass]} + titleClass={[ + bem('label', [labelAlign, { required: props.required }]), + props.labelClass, + ]} arrowDirection={props.arrowDirection} /> ); diff --git a/src/field/README.md b/src/field/README.md index fdd91957e..5d89f1984 100644 --- a/src/field/README.md +++ b/src/field/README.md @@ -344,3 +344,4 @@ The component provides the following CSS variables, which can be used to customi | --van-field-word-limit-font-size | _var(--van-font-size-sm)_ | - | | --van-field-word-limit-line-height | _16px_ | - | | --van-field-disabled-text-color | _var(--van-gray-5)_ | - | +| --van-field-required-mark-color | _var(--van-red)_ | - | diff --git a/src/field/README.zh-CN.md b/src/field/README.zh-CN.md index b50dbe56a..8479fbff9 100644 --- a/src/field/README.zh-CN.md +++ b/src/field/README.zh-CN.md @@ -363,6 +363,7 @@ export default { | --van-field-word-limit-font-size | _var(--van-font-size-sm)_ | - | | --van-field-word-limit-line-height | _16px_ | - | | --van-field-disabled-text-color | _var(--van-gray-5)_ | - | +| --van-field-required-mark-color | _var(--van-red)_ | - | ## 常见问题 diff --git a/src/field/index.less b/src/field/index.less index dc718dbb2..5d126a114 100644 --- a/src/field/index.less +++ b/src/field/index.less @@ -20,6 +20,7 @@ --van-field-word-limit-font-size: @field-word-limit-font-size; --van-field-word-limit-line-height: @field-word-limit-line-height; --van-field-disabled-text-color: @field-disabled-text-color; + --van-field-required-mark-color: @field-required-mark-color; } .van-field { @@ -39,6 +40,14 @@ &--right { text-align: right; } + + &--required { + &::before { + margin-right: 2px; + color: var(--van-field-required-mark-color); + content: '*'; + } + } } &--disabled { diff --git a/src/field/test/__snapshots__/demo.spec.ts.snap b/src/field/test/__snapshots__/demo.spec.ts.snap index efb630e62..b9702d413 100644 --- a/src/field/test/__snapshots__/demo.spec.ts.snap +++ b/src/field/test/__snapshots__/demo.spec.ts.snap @@ -183,8 +183,8 @@ exports[`should render demo and match snapshot 1`] = `
-
-
+
+
Username @@ -198,8 +198,8 @@ exports[`should render demo and match snapshot 1`] = `
-
-
+
+
Phone diff --git a/src/field/var.less b/src/field/var.less index b60ca0c49..36b0e6525 100644 --- a/src/field/var.less +++ b/src/field/var.less @@ -18,3 +18,4 @@ @field-word-limit-font-size: var(--van-font-size-sm); @field-word-limit-line-height: 16px; @field-disabled-text-color: var(--van-gray-5); +@field-required-mark-color: var(--van-red);