Skip to content

Commit

Permalink
feat: create own element for asterisk and add class in vue vanilla co…
Browse files Browse the repository at this point in the history
…ntrolWrapper eclipsesource#2238
  • Loading branch information
davewwww committed Feb 9, 2024
1 parent 5c6806f commit 7c9a8b7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/vue-vanilla/src/controls/ControlWrapper.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div v-if="visible" :id="id" :class="styles.control.root">
<label :for="id + '-input'" :class="styles.control.label">
{{ computedLabel }}
{{ computedLabel }}<span v-if="showAsterisk" :class="styles.control.asterisk">*</span>
</label>
<div :class="styles.control.wrapper">
<slot></slot>
Expand Down Expand Up @@ -78,9 +78,12 @@ export default defineComponent({
return computeLabel(
this.label,
this.required,
!!this.appliedOptions?.hideRequiredAsterisk
true
);
},
showAsterisk(): boolean {
return this.required && !this.appliedOptions?.hideRequiredAsterisk;
}
},
});
</script>
1 change: 1 addition & 0 deletions packages/vue-vanilla/src/styles/defaultStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const defaultStyles: Styles = {
textarea: 'text-area',
select: 'select',
option: 'option',
asterisk: 'asterisk',
},
verticalLayout: {
root: 'vertical-layout',
Expand Down
1 change: 1 addition & 0 deletions packages/vue-vanilla/src/styles/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Styles {
textarea?: string;
select?: string;
option?: string;
asterisk?: string;
};
dialog: {
root?: string;
Expand Down
27 changes: 27 additions & 0 deletions packages/vue-vanilla/tests/unit/complex/ObjectRenderer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ const uischema = {
scope: '#',
};

const schemaRequired = {
type: "object",
properties: {
a: {
type: 'string',
},
},
required: ["a"]
};
const uischemaRequired = {
type: 'Control',
scope: '#/properties/a',
options: {
"hideRequiredAsterisk": true
}
};

describe('ObjectRenderer.vue', () => {
it('renders a fieldset', () => {
const wrapper = mountJsonForms(
Expand Down Expand Up @@ -49,4 +66,14 @@ describe('ObjectRenderer.vue', () => {
const inputs = wrapper.findAll('input');
expect(inputs.length).to.equal(2);
});

it('renders a string input with an asterisk', () => {
const wrapper = mountJsonForms('a', schemaRequired, uischema);
expect(wrapper.find('label span.asterisk').exists()).to.be.true;
});

it('renders a string input but hide asterisk', () => {
const wrapper = mountJsonForms('a', schemaRequired, uischemaRequired);
expect(wrapper.find('label span.asterisk').exists()).to.be.false;
});
});

0 comments on commit 7c9a8b7

Please sign in to comment.