Skip to content

Commit

Permalink
Merge pull request #81 from cloudblue/feat/LITE-30032-add-required-pr…
Browse files Browse the repository at this point in the history
…op-to-inputs

LITE-30032: Add "required" prop to Select and TextField
  • Loading branch information
nerimartinez authored Apr 18, 2024
2 parents 39f71fd + 9fa1930 commit 2210667
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components/src/stories/Select.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const Validation = {
hint: 'Select the second option if you want the validation to be successful',
propValue: 'id',
propText: 'name',
required: true,
options: [
{ id: 'OBJ-123', name: 'The first object' },
{ id: 'OBJ-456', name: 'The second object' },
Expand Down Expand Up @@ -133,6 +134,7 @@ export default {
hint: 'text',
propValue: 'text',
propText: 'text',
required: 'boolean',
options: { control: 'array' },
},
};
2 changes: 2 additions & 0 deletions components/src/stories/TextField.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const Validation = {
hint: 'This is a text field with validation. The value should be an email',
value: '',
placeholder: '[email protected]',
required: true,
rules: [
(value) => !!value || 'This field is required',
(value) => isEmail(value) || 'The value is not a valid email address',
Expand All @@ -50,5 +51,6 @@ export default {
value: 'text',
placeholder: 'text',
suffix: 'text',
required: 'boolean',
},
};
13 changes: 13 additions & 0 deletions components/src/widgets/select/widget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ const props = defineProps({
type: Array,
default: () => [],
},
required: {
type: Boolean,
default: false,
},
});
const emit = defineEmits(['valueChange']);
Expand All @@ -129,6 +133,7 @@ const isFocused = ref(false);
const computedClasses = computed(() => ({
'select-input_focused': isFocused.value,
'select-input_invalid': !isValid.value,
'select-input_required': props.required,
}));
const computedOptions = computed(() =>
Expand Down Expand Up @@ -158,6 +163,14 @@ const getDisplayText = (item) => {
.select-input {
color: #212121;
&_required .select-input__label p::after {
content: '*';
margin-left: 3px;
color: #FF0000;
text-decoration: none;
display: inline-block;
}
&__selected {
height: 44px;
border-radius: 2px;
Expand Down
13 changes: 13 additions & 0 deletions components/src/widgets/textfield/widget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ const props = defineProps({
type: Array,
default: () => [],
},
required: {
type: Boolean,
default: false,
},
});
const emit = defineEmits(['input']);
Expand All @@ -86,6 +90,7 @@ const isFocused = ref(false);
const computedClasses = computed(() => ({
'text-field_focused': isFocused.value,
'text-field_invalid': !isValid.value,
'text-field_required': props.required,
}));
const removeFocus = () => (isFocused.value = false);
Expand Down Expand Up @@ -126,6 +131,14 @@ watch(localValue, (newValue) => {
line-height: 1.4;
}
&_required label::after {
content: '*';
margin-left: 3px;
color: #FF0000;
text-decoration: none;
display: inline-block;
}
&__body {
flex-grow: 1;
Expand Down

0 comments on commit 2210667

Please sign in to comment.