Skip to content
Merged
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
10 changes: 9 additions & 1 deletion components/src/widgets/select/widget.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Select', () => {

describe('render', () => {
it('renders the base component', () => {
expect(wrapper.get('.select-input__label').text()).toEqual('My select');
expect(wrapper.get('.select-input__label').text()).toEqual('My select (Optional)');
expect(wrapper.get('.select-input__hint').text()).toEqual('Some random hint');
expect(wrapper.get('.select-input__no-selection').text()).toEqual('—');
});
Expand All @@ -31,6 +31,14 @@ describe('Select', () => {
expect(menuOptions[2].text()).toEqual('baz');
});

it('does not render the "(Optional)" text in the label if required is true', async () => {
await wrapper.setProps({
required: true,
});

expect(wrapper.get('.select-input__label').text()).toEqual('My select');
});

it('renders a complex array of objects', async () => {
await wrapper.setProps({
options: [
Expand Down
14 changes: 4 additions & 10 deletions components/src/widgets/select/widget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
v-if="label"
class="select-input__label"
>
<p>{{ label }}</p>
<p>
{{ label }}
<span v-if="!required">(Optional)</span>
</p>
</div>
<ui-menu
v-bind="menuProps"
Expand Down Expand Up @@ -133,7 +136,6 @@ 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 @@ -163,14 +165,6 @@ 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
15 changes: 13 additions & 2 deletions components/src/widgets/textfield/widget.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ describe('Textfield widget', () => {
wrapper = mount(Textfield);

expect(wrapper.get('.text-field').exists()).toBeTruthy();
expect(wrapper.get('.text-field label').text()).toEqual('');
expect(wrapper.get('.text-field__input').exists()).toBeTruthy();
expect(wrapper.get('.text-field__input').element.value).toEqual('');
expect(wrapper.get('.text-field__input').attributes('placeholder')).toEqual('');
expect(wrapper.find('.text-field label').exists()).toBeFalsy();
expect(wrapper.find('.text-field__suffix').exists()).toBeFalsy();
expect(wrapper.find('.text-field_focused').exists()).toBeFalsy();
expect(wrapper.find('.text-field__input_right').exists()).toBeFalsy();
Expand All @@ -29,7 +29,7 @@ describe('Textfield widget', () => {
});

expect(wrapper.get('.text-field').exists()).toBeTruthy();
expect(wrapper.get('.text-field label').text()).toEqual('My text input');
expect(wrapper.get('.text-field label').text()).toEqual('My text input (Optional)');
expect(wrapper.get('.text-field__input').exists()).toBeTruthy();
expect(wrapper.get('.text-field__input').element.value).toEqual('Foo');
expect(wrapper.get('.text-field__input').attributes('placeholder')).toEqual(
Expand All @@ -49,6 +49,17 @@ describe('Textfield widget', () => {

expect(wrapper.get('.text-field__hint').text()).toEqual('Please fill this input');
});

it('does not render the "(Optional)" text in label if required is true', () => {
wrapper = mount(Textfield, {
props: {
label: 'My input',
required: true,
},
});

expect(wrapper.get('.text-field label').text()).toEqual('My input');
});
});

describe('validation', () => {
Expand Down
17 changes: 7 additions & 10 deletions components/src/widgets/textfield/widget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
class="text-field"
:class="computedClasses"
>
<label for="textfield">{{ label }}</label>
<label
v-if="label"
for="textfield"
>
{{ label }}
<span v-if="!required">(Optional)</span>
</label>
<div
class="text-field__wrapper"
@click="setFocus"
Expand Down Expand Up @@ -90,7 +96,6 @@ 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 @@ -131,14 +136,6 @@ 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