Creating personalized labels with Vue.js and Element UI radio button components

When using Element UI radio buttons on a form, I am attempting to personalize the label for each selection. Each radio button includes a prop called "label" where I can input my label text successfully. The problem arises when I need to apply a different style to part of the label text. Is this achievable?

For example: label="Morning (9 AM - 12 PM)", I would like to have the ability to style the time differently from "Morning". Something like

label="Morning <span>(9 AM - 12 PM)</span>"

    <el-form-item
                prop="selfBestTimeToContact"
                class="form-item--radio form-item--radio--radio-adjacent"
                :show-message="false"
              >
                <el-radio-group
                  v-model="formData.selfBestTimeToContact"
                  ref="selfBestTimeToContact"
                >
                  <ol>
                    <li class="radio-list-item">
                      <el-radio
                        id="selfBestTimeToContactMorning"
                        label="Morning (9 AM - 12 PM)"
                        name="selfBestTimeToContact"
                        class="radio--bold"
                      />
                      <p>Test</p>
                    </li>

                    <li class="radio-list-item">
                      <el-radio
                        id="selfBestTimeToContactAfternoon"
                        label="Afternoon (12 PM - 5 PM)"
                        name="selfBestTimeToContact"
                        class="radio--bold"
                      />
                    </li>

                    <li class="radio-list-item">
                      <el-radio
                        id="selfBestTimeToContactEvening"
                        label="Evening (5 PM - 8 PM)"
                        name="selfBestTimeToContact"
                        class="radio--bold radio-label"
                      />
                    </li>
                  </ol>
                </el-radio-group>
              </el-form-item>

Answer №1

If the default slot of el-radio is provided, it will be displayed as the label (with the label attribute used as the value). This allows you to easily add styling to your label using markup inside:

<template>
  <el-radio>Morning <span class="time">(9 AM - 12 PM)</span></el-radio>
</template>

<style>
.time {
  font-weight: bold;
}
</style>

Check out the demo

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why does WebdriverIO send a POST request for an unused webelement?

Exploring the capabilities of webdriverIO has been quite enjoyable! There are many features of this framework that I already appreciate. In my investigation, I wanted to see how WebdriverIO handles non-existing elements and lazy element loading in this te ...

Maximizing efficiency when retrieving information from JSON files

Is there a way to optimize data retrieval for faster loading and determining data length without loading the entire JSON data? Check out this code snippet: const url = "https://jsonplaceholder.typicode.com/comments"; const [data, setData] = useState([] ...

Issue with displaying the glyphicon-chevron on the carousel control

Currently, I'm in the process of incorporating a straightforward modal into my gallery design. I have a slide carousel positioned at the top of the page, while at the bottom, there are thumbnails of the gallery. While the slide carousel control butto ...

The Vuetify Treeview feature ensures that only child nodes are selectable within the tree structure

Is there a way to make only child elements in a Treeview selectable? I've stumbled upon a clever workaround where I exclude setting selectable on the treeview and instead add checkboxes like this: <v-treeview item-key="id" :items="items" ...

The issue with Vuetify's external pagination is that it is not showing the

I'm currently working on implementing pagination for a v-data-table component. I've referred to the Vuetify example documentation (available here) but seem to be facing some issues. Upon creation, my component fetches data from the backend and po ...

Equivalent Vue class for setup() method that utilizes useI18n() to destructure the 't' method with options inheritLocale set to true and useScope set to 'local'

Implementing i18n for translating purposes in Vue 3 is something I am trying to do. Here's how I have done it: const { t } = useI18n({ inheritLocale: true, useScope: 'local' }) Then, I used this code snippet to actually tran ...

Guide on creating a 4-point perspective transform with HTML5 canvas and three.js

First off, here's a visual representation of my objective: https://i.stack.imgur.com/5Uo1h.png (Credit for the photo: ) The concise question How can I use HTML5 video & canvas to execute a 4-point perspective transform in order to display only ...

Having divs stacked on top of each other with one positioned fixed and the other

In my HTML document, there is a main div element called container that contains several child elements also in the form of divs. One specific child div, named top_bar, has its positioning set to fixed, while the rest of the child divs have relative posit ...

How to switch around div elements using CSS

There are two unordered list items in a container div and one swap button. When the swap button is clicked, the order of items needs to change. This functionality can be achieved using the following swap function. var ints = [ "1", "2", "3", "4" ], ...

Display your StencilJs component in a separate browser window

Looking for a solution to render a chat widget created with stenciljs in a new window using window.open. When the widget icon is clicked, a new window should open displaying the current state while navigating on the website, retaining the styles and functi ...

Performing ad-hoc queries on a Postgresql database using Node.js and Express to manipulate row data

I am faced with a challenge of selecting one entry randomly from a table containing 46 entries, and then passing the data from that particular query to my handlebars files. I am unsure about how to approach the task of randomly querying the database and re ...

Error message: The function Vue.use is not being caught as a TypeError

Recently, I've started learning VueJS and now I'm attempting to swap out the <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="89fffcecc9bba7bf">[email protected] ...

Having trouble with jQuery in Blogger?

I'm having trouble installing a Facebook slider tab on a friend's blog and I can't seem to get it to work. Here's the link to her blog: And here's the tutorial I'm following: jQuery is already installed on the blog (you can ...

What steps can be taken to adjust the alignment of a Bootstrap Dropright menu so that it opens in an upward direction instead of the standard downward

My dropdown menu is dropping towards the right correctly, but it is going downwards and getting hidden under my page. I want it to open upwards instead of downwards. I attempted to adjust the CSS, adding bottom:0 to the dropdown-menu, but unfortunately, i ...

Strategies for smoothly navigating the page to a specific div every time

Currently, I am working on a form that requires submitting multiple child forms. To enhance user experience, I have incorporated jQuery functionality to display a message at the top of the page upon each submission. Now, my goal is to implement a feature w ...

Attempting to create a fixed div at a specific position, however, an unexpected Uncaught TypeError disrupted additional code functionality

Is there a way to make a div stay fixed in place while scrolling, but then unstick at a specific point? I found some code that seemed to work for this purpose, but unfortunately it caused an error that affected other jQuery scripts. The console displayed t ...

Unable to Show the Contents of the Item - AngularJS

I'm in the process of developing an application that will showcase job details within a modal window based on the selected template. To achieve this, I've integrated ui.bootstrap and ui.router. However, I'm encountering difficulties in displ ...

Locate the unique symbol within an array

I am facing a challenge with validating user input in an input box where alphanumeric values are allowed along with certain special characters. I need to display an error message if the user enters a special character that is not supported by my applicatio ...

How can I create responsive buttons with icons using material-ui?

I'm working with a material-ui Button that has a startIcon, and I need to hide the button text on smaller screens while still showing the icon. One common solution would be to use the useMediaQuery hook to identify the browser size and render a diffe ...

What steps can I follow to set up the `I18n Ally` VsCode plugin to access my localizations from a single file?

I am currently utilizing the vue-i18n library for translating my Vue project and I would like to employ the "I18n Ally" VS Code extension to manage these translations. The default folder structure recommended by this extension is as follows: lo ...