Skip to content

更新必填标签样式,支持左右位置 #3221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,4 @@
"@types/react": "^18.2.57",
"@types/react-dom": "^18.2.19"
}
}
}
4 changes: 2 additions & 2 deletions src/packages/calendar/__tests__/calendar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,13 @@ test('range select event when click item', () => {
const start = container.querySelectorAll(
'.nut-calendar-day-active .nut-calendar-day-day'
)[0]
expect(start.innerHTML).toBe('10')
expect(start.innerHTML).toBe('14')

const calendarMonthDay2 = container.querySelectorAll('.nut-calendar-day')[20]
fireEvent.click(calendarMonthDay2)
expect(onDayClick).toBeCalled()
const next = container.querySelectorAll(
'.nut-calendar-day-choose .nut-calendar-day-day'
)[0]
expect(next.innerHTML).toBe('11')
expect(next.innerHTML).toBe('15')
})
15 changes: 14 additions & 1 deletion src/packages/form/__tests__/form.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,20 @@ test('form set required', () => {
</Form>
)
expect(
container.querySelectorAll('.nut-form-item-label-required')
container.querySelectorAll('.nut-form-item-label-required-left')
).toHaveLength(1)
})

test('form set starPosition', () => {
const { container } = render(
<Form initialValues={{ username: 'NutUI-React' }} starPosition="right">
<Form.Item name="username" required label="UserName">
<Input />
</Form.Item>
</Form>
)
expect(
container.querySelectorAll('.nut-form-item-label-required-right')
).toHaveLength(1)
})

Expand Down
10 changes: 9 additions & 1 deletion src/packages/formitem/formitem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@
text-align: $form-item-label-text-align;
}

&-label-required {
&-label-required-left {
color: $form-item-required-color;
margin-right: $form-item-required-margin-right;
display: block;
position: absolute;
left: -0.8em;
}
&-label-required-right {
color: $form-item-required-color;
margin-right: $form-item-required-margin-right;
display: block;
// position: absolute;
// left: -0.8em;
}

.nut-form-item-labeltxt {
font-size: $form-item-label-font-size;
Expand Down Expand Up @@ -129,6 +136,7 @@
/* position */

.nut-form-item-label-right {
position: relative;
justify-content: flex-end;
padding-right: 24px;
white-space: nowrap;
Expand Down
4 changes: 3 additions & 1 deletion src/packages/formitem/formitem.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ export class FormItem extends React.Component<

const { starPosition } = this.context.formInstance
const renderStar = (required || requiredInRules) && (
<Text className="nut-form-item-label-required required">*</Text>
<Text className={`nut-form-item-label-required-${starPosition} required`}>
*
</Text>
)
const renderLabel = (
<>
Expand Down
4 changes: 3 additions & 1 deletion src/packages/formitem/formitem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ export class FormItem extends React.Component<

const { starPosition } = this.context.formInstance
const renderStar = (required || requiredInRules) && (
<div className="nut-form-item-label-required required">*</div>
<div className={`nut-form-item-label-required-${starPosition} required`}>
*
</div>
)
const renderLabel = (
<>
Expand Down