Skip to content

Commit 513629b

Browse files
authored
Merge pull request #1624 from sheinsight/feat/form-keep-error-above
feat: Form 新增 keepErrorAbove 属性,错误信息显示在提示信息上方
2 parents 76cc770 + c4b3897 commit 513629b

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed

docs/api/shineout/form.ts

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "sheinx",
33
"private": true,
4-
"version": "3.9.9-beta.15",
4+
"version": "3.9.9-beta.16",
55
"description": "A react library developed with sheinx",
66
"module": "dist/index.js",
77
"types": "dist/index.d.ts",

packages/base/src/form/form-item.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const FormItem = (props: FormItemProps) => {
1212
const { children, jssStyle, className, style, label, tip, required, ...rest } = props;
1313
const formItemClasses = jssStyle?.formItem?.() as FormItemClasses;
1414
const { Provider: FormItemContextProvider, ProviderValue, labelConfig, errors, showError, attributes } = useFormItem();
15-
const { labelWidth, labelAlign, labelVerticalAlign, inline, keepErrorHeight, keepErrorBelow, colon } = {
15+
const { labelWidth, labelAlign, labelVerticalAlign, inline, keepErrorHeight, keepErrorBelow, keepErrorAbove, colon } = {
1616
...labelConfig,
1717
...rest,
1818
};
@@ -131,9 +131,11 @@ const FormItem = (props: FormItemProps) => {
131131
>
132132
<FormItemContextProvider value={{ ...ProviderValue, label: labelText }}>{children}</FormItemContextProvider>
133133

134-
{!!tip && (!showError || keepErrorBelow) && <div ref={labelTipRef} className={formItemClasses?.tip}>{tip}</div>}
134+
{keepErrorAbove && renderError()}
135135

136-
{renderError()}
136+
{!!tip && (!showError || keepErrorBelow || keepErrorAbove) && <div ref={labelTipRef} className={formItemClasses?.tip}>{tip}</div>}
137+
138+
{!keepErrorAbove && renderError()}
137139
</div>
138140
</div>
139141
);

packages/hooks/src/components/use-form/use-form.type.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ export interface FormLabelConfig {
8787
* @version 3.7.0
8888
*/
8989
keepErrorBelow?: boolean;
90+
91+
/**
92+
* @en Whether to keep the error message above the tip of the form item, the default is false. Controls the display position of error messages. When enabled, error messages are always displayed above the tip property of the form item. The opposite of keepErrorBelow. Suitable for scenarios where error messages need to be displayed closer to the input. Note: When enabled, keepErrorHeight becomes invalid
93+
* @cn 是否保持错误信息在提示信息上方。控制错误信息的显示位置。开启后错误信息始终显示在表单项的 tip 属性上方。与 keepErrorBelow 相反。适用于错误信息需要更靠近输入框的场景。注意:开启后会使 keepErrorHeight 失效
94+
* @default false
95+
* @version 3.9.9
96+
*/
97+
keepErrorAbove?: boolean;
9098
/**
9199
* @en When inline is true, the form is horizontal layout. Arranges form items horizontally, suitable for simple single-line forms or filter forms. When enabled, form items will be displayed on the same line with automatic line wrapping. Usually used for search conditions, filters and other scenarios that need to save vertical space
92100
* @cn 是否水平布局。将表单项横向排列,适用于简单的单行表单或筛选表单。开启后表单项会在同一行显示,自动换行。通常用于搜索条件、筛选器等需要节省垂直空间的场景

packages/shineout/src/form/__doc__/changelog.cn.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 3.9.9-beta.16
2+
2026-02-14
3+
### 🆕 Feature
4+
- `Form` 新增 `keepErrorAbove` 属性,错误信息独占一行,不再覆盖提示信息 ([#1624](https://github.com/sheinsight/shineout-next/pull/1624))
5+
6+
17
## 3.9.8-beta.1
28
2026-01-09
39
### 🆕 Feature

packages/shineout/src/form/__example__/006-validate-04-height.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* cn - 校验样式
33
* -- 使用 `keepErrorHeight` 使得单行错误提示不会撑开页面高度
4-
* -- 使用 `keepErrorBelow` 同时出现提示信息和校验错误信息时,提示信息不会被遮挡
4+
* -- 使用 `keepErrorAbove` 同时出现提示信息和校验错误信息时,错误信息显示在提示信息上方
55
* en - validate style
66
* -- Use `keepErrorHeight` so that a single-line error prompt will not stretch the page height
7-
* -- Use `keepErrorBelow` so that when both prompt information and validation error information appear, the prompt information will not be blocked
7+
* -- Use `keepErrorAbove` so that when both prompt information and validation error information appear, the error message is displayed above the tip
88
*/
99

1010
import React, { useState } from 'react';
@@ -147,7 +147,7 @@ const App: React.FC = () => {
147147
style={{ maxWidth: 500 }}
148148
onSubmit={(d) => console.log(d)}
149149
>
150-
<Form.Item required label='Email' tip='88888' keepErrorBelow>
150+
<Form.Item required label='Email' tip='88888' keepErrorAbove>
151151
<Input name='email' title='Email' rules={[rules.required, rules.email]} clearable />
152152
</Form.Item>
153153

@@ -159,7 +159,7 @@ const App: React.FC = () => {
159159
required
160160
label='Password'
161161
tip='At least one letter, one numeral, and 6 - 20 characters.'
162-
keepErrorBelow
162+
keepErrorAbove
163163
>
164164
<Input
165165
name='password'
@@ -170,7 +170,7 @@ const App: React.FC = () => {
170170
/>
171171
</Form.Item>
172172

173-
<Form.Item required label='Age' tip='between 18 and 60' keepErrorBelow>
173+
<Form.Item required label='Age' tip='between 18 and 60' keepErrorAbove>
174174
<Input
175175
name='age'
176176
title='Age'
@@ -198,7 +198,7 @@ const App: React.FC = () => {
198198
required
199199
label='Favorite Colors'
200200
tip='select your favorite colors'
201-
keepErrorBelow
201+
keepErrorAbove
202202
>
203203
<Checkbox.Group
204204
name='colors'

0 commit comments

Comments
 (0)