CSR-222: refactor with emit for click event
This commit is contained in:
parent
86191a16fe
commit
96a5cdf46e
8 changed files with 73 additions and 34 deletions
|
|
@ -7,8 +7,8 @@
|
||||||
</span>
|
</span>
|
||||||
<buttonBack
|
<buttonBack
|
||||||
v-if="hasBackButton"
|
v-if="hasBackButton"
|
||||||
:backButtonAction="backButtonAction"
|
|
||||||
:backButtonAccessibleText="backButtonAccessibleText"
|
:backButtonAccessibleText="backButtonAccessibleText"
|
||||||
|
@click-event="clickEvent"
|
||||||
/>
|
/>
|
||||||
</h5>
|
</h5>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -24,11 +24,15 @@ export default {
|
||||||
text: String,
|
text: String,
|
||||||
hasBackButton: Boolean,
|
hasBackButton: Boolean,
|
||||||
backButtonAccessibleText: String,
|
backButtonAccessibleText: String,
|
||||||
backButtonAction: Function,
|
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
buttonBack,
|
buttonBack,
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
clickEvent() {
|
||||||
|
this.$emit('click-event');
|
||||||
}
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
:text="funnelSubHeaderWidget.HeaderText"
|
:text="funnelSubHeaderWidget.HeaderText"
|
||||||
:hasBackButton="true"
|
:hasBackButton="true"
|
||||||
backButtonAccessibleText="Change Vehicle Year"
|
backButtonAccessibleText="Change Vehicle Year"
|
||||||
:backButtonAction="backButtonAction"
|
@click-event="backButtonAction"
|
||||||
class="Header"
|
class="Header"
|
||||||
/>
|
/>
|
||||||
<makeQuestion v-model="selectedMake" ref="makeQuestion" />
|
<makeQuestion v-model="selectedMake" ref="makeQuestion" />
|
||||||
|
|
@ -67,7 +67,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
backButtonAction: function () {
|
backButtonAction() {
|
||||||
// route to move backwards
|
// route to move backwards
|
||||||
this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route);
|
this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
:text="funnelSubHeaderWidget.HeaderText"
|
:text="funnelSubHeaderWidget.HeaderText"
|
||||||
:hasBackButton="true"
|
:hasBackButton="true"
|
||||||
backButtonAccessibleText="Change Vehicle Make"
|
backButtonAccessibleText="Change Vehicle Make"
|
||||||
:backButtonAction="backButtonAction"
|
@click-event="backButtonAction"
|
||||||
class="Header"
|
class="Header"
|
||||||
/>
|
/>
|
||||||
<modelQuestion v-model="selectedModel" ref="modelQuestion" />
|
<modelQuestion v-model="selectedModel" ref="modelQuestion" />
|
||||||
|
|
@ -67,7 +67,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
backButtonAction: function () {
|
backButtonAction() {
|
||||||
// route to move backwards
|
// route to move backwards
|
||||||
this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route);
|
this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
:text="funnelSubHeaderWidget.HeaderText"
|
:text="funnelSubHeaderWidget.HeaderText"
|
||||||
:hasBackButton="true"
|
:hasBackButton="true"
|
||||||
backButtonAccessibleText="Change Vehicle Model"
|
backButtonAccessibleText="Change Vehicle Model"
|
||||||
:backButtonAction="backButtonAction"
|
@click-event="backButtonAction"
|
||||||
class="Header"
|
class="Header"
|
||||||
/>
|
/>
|
||||||
<styleQuestion v-model="selectedStyle" ref="styleQuestion" />
|
<styleQuestion v-model="selectedStyle" ref="styleQuestion" />
|
||||||
|
|
@ -67,7 +67,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
backButtonAction: function () {
|
backButtonAction() {
|
||||||
// route to move backwards
|
// route to move backwards
|
||||||
this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route);
|
this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<button
|
<button
|
||||||
v-if="backButtonAction"
|
@click="handleClick"
|
||||||
@click="backButtonAction"
|
|
||||||
class="back-button-wrapper p-3"
|
class="back-button-wrapper p-3"
|
||||||
:aria-label="backButtonAccessibleText"
|
:aria-label="backButtonAccessibleText"
|
||||||
>
|
>
|
||||||
|
|
@ -20,12 +19,13 @@ export default {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
default: "",
|
default: "",
|
||||||
},
|
|
||||||
backButtonAction: {
|
|
||||||
type: Function,
|
|
||||||
default: null,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
handleClick() {
|
||||||
|
this.$emit('click-event');
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ describe("list-button.vue", () => {
|
||||||
groupName: "TestGroup",
|
groupName: "TestGroup",
|
||||||
loaderColor: "blue",
|
loaderColor: "blue",
|
||||||
loaderPosition: "right",
|
loaderPosition: "right",
|
||||||
|
loaderEnabled: "true",
|
||||||
sizeInRem: "1.5",
|
sizeInRem: "1.5",
|
||||||
errorMessage: "null",
|
errorMessage: "null",
|
||||||
},
|
},
|
||||||
|
|
@ -20,7 +21,7 @@ describe("list-button.vue", () => {
|
||||||
const label = wrapper.find("label");
|
const label = wrapper.find("label");
|
||||||
const paragraph = wrapper.find("span");
|
const paragraph = wrapper.find("span");
|
||||||
|
|
||||||
await label.trigger("click");
|
await input.trigger("click");
|
||||||
|
|
||||||
expect(input.attributes()).toEqual({
|
expect(input.attributes()).toEqual({
|
||||||
id: "2023",
|
id: "2023",
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<template>
|
<template>
|
||||||
<!-- IMPORTANT: Refrain from using more than 4 horizontal buttons on desktop, 3 on mobile. -->
|
<!-- IMPORTANT: Refrain from using more than 4 horizontal buttons on desktop, 3 on mobile. -->
|
||||||
<div v-if="isMultiSelect" class="list-group list-button-horizontal d-flex flex-column w-100 mb-2">
|
<div v-if="isMultiSelect" class="list-group list-button-horizontal d-flex flex-column w-100 mb-2">
|
||||||
<input type="checkbox" :id="buttonID" :name="groupName" :value="buttonID" :aria-required="isRequired">
|
<input type="checkbox" :id="buttonID" :name="groupName" :value="buttonID" :aria-required="isRequired" @keyup.space="handleClick(buttonID)" @click="handleClick(buttonID)">
|
||||||
<label tabindex="-1" aria-checked="false" :for="buttonID" :aria-labelledby="buttonID" class="d-flex flex-column justify-content-center py-3 px-4" :class="isFirstOrLastButton">
|
<label tabindex="-1" aria-checked="false" :for="buttonID" :aria-labelledby="buttonID" class="d-flex flex-column justify-content-center py-3 px-4" :class="isFirstOrLastButton">
|
||||||
<span class="m-0" :class="[this.textPosition]">{{buttonID}}</span>
|
<span class="m-0" :class="[this.textPosition]">{{buttonID}}</span>
|
||||||
<span v-if="buttonLabelSubCopy" class="m-0 small" :class="[this.textPosition]">{{buttonLabelSubCopy}}</span>
|
<span v-if="buttonLabelSubCopy" class="m-0 small" :class="[this.textPosition]">{{buttonLabelSubCopy}}</span>
|
||||||
|
|
@ -11,8 +11,8 @@
|
||||||
<p class="small">{{errorMessage}}</p>
|
<p class="small">{{errorMessage}}</p>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="col list-group list-button-horizontal d-flex flex-column mb-2">
|
<div v-else class="col list-group list-button-horizontal d-flex flex-column mb-2">
|
||||||
<input type="radio" :id="buttonID" :name="groupName" :value="buttonID" aria-required="true" @keyup.space="displayLoader()"/>
|
<input type="radio" :id="buttonID" :name="groupName" :value="buttonID" aria-required="true" @keyup.space="handleClick(buttonID)" @click="handleClick(buttonID)" />
|
||||||
<label tabindex="-1" aria-checked="false" :for="buttonID" :aria-labelledby="buttonID" class="d-flex flex-column justify-content-center py-3 px-4" :class="isFirstOrLastButton" @click="displayLoader()">
|
<label tabindex="-1" aria-checked="false" :for="buttonID" :aria-labelledby="buttonID" class="d-flex flex-column justify-content-center py-3 px-4" :class="isFirstOrLastButton">
|
||||||
<span class="m-0" :class="[this.textPosition]">{{buttonID}}</span>
|
<span class="m-0" :class="[this.textPosition]">{{buttonID}}</span>
|
||||||
<span v-if="buttonLabelSubCopy" class="m-0 small" :class="[this.textPosition]">{{buttonLabelSubCopy}}</span>
|
<span v-if="buttonLabelSubCopy" class="m-0 small" :class="[this.textPosition]">{{buttonLabelSubCopy}}</span>
|
||||||
<span v-if="screenReaderOnlyText" class="sr-only">{{screenReaderOnlyText}}</span>
|
<span v-if="screenReaderOnlyText" class="sr-only">{{screenReaderOnlyText}}</span>
|
||||||
|
|
@ -23,7 +23,10 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { toRefs } from 'vue';
|
||||||
|
import { useField } from 'vee-validate';
|
||||||
import loader from "@/ux-components/loader/loader";
|
import loader from "@/ux-components/loader/loader";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "listButtonHorizontal",
|
name: "listButtonHorizontal",
|
||||||
props: {
|
props: {
|
||||||
|
|
@ -34,15 +37,17 @@ export default {
|
||||||
screenReaderOnlyText: String, /* Optional, copy to be read by screenreader */
|
screenReaderOnlyText: String, /* Optional, copy to be read by screenreader */
|
||||||
textPosition: String, /* Optional, use Bootstrap classes: text-start, text-center, text-end. Default (empty) is text-start */
|
textPosition: String, /* Optional, use Bootstrap classes: text-start, text-center, text-end. Default (empty) is text-start */
|
||||||
errorMessage: String, /* Optional, if there is an error message to be displayed */
|
errorMessage: String, /* Optional, if there is an error message to be displayed */
|
||||||
|
loaderEnabled: Boolean, /* Optional, need to include this for loader to be used at all */
|
||||||
loaderColor: String, /* Specify color of loader/spinner. Options are blue, red, green, white, black. Default is blue */
|
loaderColor: String, /* Specify color of loader/spinner. Options are blue, red, green, white, black. Default is blue */
|
||||||
loaderPosition: String, /* Specify horizontal position of loader/spinner. Options are center, right, left */
|
loaderPosition: String, /* Specify horizontal position of loader/spinner. Options are center, right, left */
|
||||||
sizeInRem: [Number,String], /* Specify size of loader/spinner in rem. Example: 1.5 (equals 24px (16x1.5)) */
|
sizeInRem: [Number,String], /* Specify size of loader/spinner in rem. Example: 1.5 (equals 24px (16x1.5)) */
|
||||||
totalInGroup: Number, /* Required, total number of buttons in group. Used to tell first and last in group to apply border radius. */
|
totalInGroup: Number, /* Required, total number of buttons in group. Used to tell first and last in group to apply border radius. */
|
||||||
positionInGroup: Number /* Rquired, position of button in group. Example, 1,2,3 */
|
positionInGroup: Number, /* Required, position of button in group. Example, 1,2,3 */
|
||||||
|
isRequired: Boolean,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isError: false,
|
hasError: false,
|
||||||
isLoaderDisplayed: false,
|
isLoaderDisplayed: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
@ -50,6 +55,10 @@ export default {
|
||||||
displayLoader() {
|
displayLoader() {
|
||||||
this.isLoaderDisplayed = true;
|
this.isLoaderDisplayed = true;
|
||||||
},
|
},
|
||||||
|
handleClick(value) {
|
||||||
|
this.loaderEnabled && this.displayLoader();
|
||||||
|
this.handleChange(value);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
loader,
|
loader,
|
||||||
|
|
@ -65,8 +74,20 @@ export default {
|
||||||
return className;
|
return className;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
setup(props) {
|
||||||
|
const { groupName, buttonID } = toRefs(props);
|
||||||
|
const { checked, handleChange } = useField(groupName, undefined, {
|
||||||
|
type: props.isMultiSelect ? "checkbox" : "radio",
|
||||||
|
checkedValue: buttonID
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
checked,
|
||||||
|
handleChange,
|
||||||
|
};
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.list-button-horizontal {
|
.list-button-horizontal {
|
||||||
input[type="radio"],
|
input[type="radio"],
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<!-- Heavily documented below -->
|
<!-- Heavily documented below -->
|
||||||
<div v-if="isMultiSelect" class="list-card w-100 rounded-3 d-flex align-items-center" :class="{'error': hasError}">
|
<div v-if="isMultiSelect" class="list-card w-100 rounded-3 d-flex align-items-center" :class="{'error': hasError}">
|
||||||
<input type="checkbox" :id="buttonID" :name="groupName" :value="buttonLabel" :aria-required="isRequired" />
|
<input type="checkbox" :id="buttonID" :name="groupName" :value="buttonLabel" :aria-required="isRequired" @keyup.space="handleChange(buttonLabel)" @click="handleChange(buttonLabel)" />
|
||||||
<label :for="buttonID" class="d-flex flex-column w-100 align-items-center pt-4 pb-2" tabindex="1">
|
<label :for="buttonID" class="d-flex flex-column w-100 align-items-center pt-4 pb-2" tabindex="1">
|
||||||
<img class="order-1" v-bind:src="require(`@/assets/img/icons/${buttonImage}`)" v-bind:alt="altText" />
|
<img class="order-1" v-bind:src="require(`@/assets/img/icons/${buttonImage}`)" v-bind:alt="altText" />
|
||||||
<p class="small m-0 order-3">{{buttonLabel}}</p>
|
<p class="small m-0 order-3">{{buttonLabel}}</p>
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="isRadio" class="list-card w-100 rounded-3 d-flex align-items-center" :class="{'error': hasError}">
|
<div v-else-if="isRadio" class="list-card w-100 rounded-3 d-flex align-items-center" :class="{'error': hasError}">
|
||||||
<input type="radio" :id="buttonID" :name="groupName" :value="buttonID" :aria-required="isRequired" />
|
<input type="radio" :id="buttonID" :name="groupName" :value="buttonID" :aria-required="isRequired" @keyup.space="handleChange(buttonLabel)" @click="handleChange(buttonLabel)" />
|
||||||
<label :for="buttonID" class="d-flex flex-column w-100 align-items-center pt-4 pb-2" tabindex="1">
|
<label :for="buttonID" class="d-flex flex-column w-100 align-items-center pt-4 pb-2" tabindex="1">
|
||||||
<img class="order-1" v-bind:src="require(`@/assets/img/icons/${buttonImage}`)" v-bind:alt="altText" />
|
<img class="order-1" v-bind:src="require(`@/assets/img/icons/${buttonImage}`)" v-bind:alt="altText" />
|
||||||
<p class="small mt-2 mb-0 order-2">{{buttonLabel}}</p>
|
<p class="small mt-2 mb-0 order-2">{{buttonLabel}}</p>
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="isMultiSelectHorizontal" class="list-card horizontal w-100 rounded-3 d-flex align-items-center" :class="{'error': hasError}">
|
<div v-else-if="isMultiSelectHorizontal" class="list-card horizontal w-100 rounded-3 d-flex align-items-center" :class="{'error': hasError}">
|
||||||
<input type="checkbox" :id="buttonID" :name="groupName" :value="buttonLabel" :aria-required="isRequired" />
|
<input type="checkbox" :id="buttonID" :name="groupName" :value="buttonLabel" :aria-required="isRequired" @keyup.space="handleChange(buttonLabel)" @click="handleChange(buttonLabel)" />
|
||||||
<label :for="buttonID" class="d-flex flex-row w-100 align-items-center py-3 ps-3 pe-8" tabindex="1" :class="{'checkboxTop': buttonLabelSubCopy}">
|
<label :for="buttonID" class="d-flex flex-row w-100 align-items-center py-3 ps-3 pe-8" tabindex="1" :class="{'checkboxTop': buttonLabelSubCopy}">
|
||||||
<img class="ms-auto order-3" v-bind:src="require(`@/assets/img/icons/${buttonImage}`)" v-bind:alt="altText" />
|
<img class="ms-auto order-3" v-bind:src="require(`@/assets/img/icons/${buttonImage}`)" v-bind:alt="altText" />
|
||||||
<div class="order-2">
|
<div class="order-2">
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="isRadioHorizontal" class="list-card horizontal w-100 rounded-3 d-flex align-items-center" :class="{'error': hasError}">
|
<div v-else-if="isRadioHorizontal" class="list-card horizontal w-100 rounded-3 d-flex align-items-center" :class="{'error': hasError}">
|
||||||
<input type="radio" :id="buttonID" :name="groupName" :value="buttonLabel" :aria-required="isRequired" />
|
<input type="radio" :id="buttonID" :name="groupName" :value="buttonLabel" :aria-required="isRequired" @keyup.space="handleChange(buttonLabel)" @click="handleChange(buttonLabel)" />
|
||||||
<label :for="buttonID" class="d-flex flex-row w-100 align-items-center py-3 ps-3 pe-8" tabindex="1" :class="{'checkboxTop': buttonLabelSubCopy}">
|
<label :for="buttonID" class="d-flex flex-row w-100 align-items-center py-3 ps-3 pe-8" tabindex="1" :class="{'checkboxTop': buttonLabelSubCopy}">
|
||||||
<img class="ms-auto order-3" v-bind:src="require(`@/assets/img/icons/${buttonImage}`)" v-bind:alt="altText" />
|
<img class="ms-auto order-3" v-bind:src="require(`@/assets/img/icons/${buttonImage}`)" v-bind:alt="altText" />
|
||||||
<div class="order-2">
|
<div class="order-2">
|
||||||
|
|
@ -39,14 +39,16 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { useField } from 'vee-validate';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "listCard",
|
name: "listCard",
|
||||||
props: {
|
props: {
|
||||||
//Must choose one of the following four options
|
//Must choose one of the following four options
|
||||||
isMultiSelect: Boolean,//Defines use as checkbox
|
isMultiSelect: Boolean, //Defines use as checkbox
|
||||||
isRadio: Boolean,//Defines use as radio button
|
isRadio: Boolean, //Defines use as radio button
|
||||||
isMultiSelectHorizontal: Boolean,//Defines use as horizontal checkbox
|
isMultiSelectHorizontal: Boolean, //Defines use as horizontal checkbox
|
||||||
isRadioHorizontal: Boolean,//Defines use as horizontal radio button
|
isRadioHorizontal: Boolean, //Defines use as horizontal radio button
|
||||||
//end must choose
|
//end must choose
|
||||||
buttonImage: String,//Optional: File name of image
|
buttonImage: String,//Optional: File name of image
|
||||||
buttonLabel: String,//Required: Label text
|
buttonLabel: String,//Required: Label text
|
||||||
|
|
@ -55,7 +57,18 @@ export default {
|
||||||
groupName: String,//Rquired: Unique
|
groupName: String,//Rquired: Unique
|
||||||
buttonLabelSubCopy: String,//Optional: sub text
|
buttonLabelSubCopy: String,//Optional: sub text
|
||||||
hasError: Boolean//Used to show error state
|
hasError: Boolean//Used to show error state
|
||||||
}
|
},
|
||||||
|
// eslint-disable-next-line vue/no-setup-props-destructure
|
||||||
|
// setup({ groupName, value }) {
|
||||||
|
// const { checked, handleChange } = useField(groupName, undefined, {
|
||||||
|
// type: "radio",
|
||||||
|
// checkedValue: value
|
||||||
|
// });
|
||||||
|
// return {
|
||||||
|
// checked,
|
||||||
|
// handleChange,
|
||||||
|
// };
|
||||||
|
// },
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue