Skip to content

Commit 9cf6d29

Browse files
authored
fix: required items field is not marked (#746)
* fix: required items field is not marked * fix: use tailwind * fix: test case change
1 parent d2a966a commit 9cf6d29

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

shell/app/common/__tests__/components/edit-field.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ describe('EditField', () => {
4343
);
4444
wrapper.find('.common-edit-field').children('div').at(1).simulate('click');
4545
expect(wrapper.find('.suffix')).toExist();
46-
expect(wrapper.find('.ant-form-item-required')).toExist();
46+
expect(wrapper.find('[data-required="* "]')).toExist();
4747
expect(wrapper.find('.color-text-sub')).toExist();
4848
expect(wrapper.find('input').prop('value')).toBe('erda.cloud');
4949
wrapper.setProps({
5050
labelStyle: undefined,
5151
showRequiredMark: false,
5252
});
53-
expect(wrapper.find('.ant-form-item-required')).not.toExist();
53+
expect(wrapper.find('[data-required="* "]')).not.toExist();
5454
expect(wrapper.find('.color-text')).toExist();
5555
wrapper.setProps({
5656
value: undefined,

shell/app/common/components/edit-field.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,11 @@ export const EditField = React.forwardRef((props: IProps, _compRef) => {
281281
<div className={`common-edit-field ${className}`}>
282282
{label && (
283283
<div
284+
data-required={showRequiredMark ? '* ' : ''}
284285
className={classnames(
285286
labelStyle === 'desc' ? 'color-text-sub' : 'color-text',
286287
'mb4',
287-
showRequiredMark ? 'ant-form-item-required' : '',
288+
showRequiredMark ? 'before:required' : '',
288289
)}
289290
style={{ paddingLeft: '10px' }}
290291
>

shell/tailwind.config.js

+14
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ module.exports = {
106106
extend: {},
107107
},
108108
plugins: [
109+
plugin(({ addVariant, e }) => {
110+
addVariant('before', ({ modifySelectors, separator }) => {
111+
modifySelectors(({ className }) => {
112+
return `.${e(`before${separator}${className}`)}::before`;
113+
});
114+
});
115+
}),
109116
plugin(({ addUtilities }) => {
110117
const newUtilities = {
111118
'.nowrap': {
@@ -118,8 +125,15 @@ module.exports = {
118125
cursor: 'not-allowed',
119126
},
120127
};
128+
const contentUtilities = {
129+
'.required': {
130+
content: 'attr(data-required)',
131+
color: '#f5222d',
132+
},
133+
};
121134

122135
addUtilities(newUtilities, ['responsive', 'hover']);
136+
addUtilities(contentUtilities, ['before']);
123137
}),
124138
],
125139
purge: {

0 commit comments

Comments
 (0)