DroidBarber
DroidBarber

Reputation: 35

How to capitalize title tooltip in Vue.js

How do I capitalize only the first letter of the title tooltip (from a span)? I tried using CSS text-transform: capitalize;, but it didn't work.

<template lang="pug">
    .cell-audience-status-dot(:class="{'overflow-initial': type === 'actions'}")
        .cell-content.audiences(v-if="data !== 'never_activated'")
            .icon-wrapper(:class="{ active : activeMenu === 'activeSegments' && openedSegments.includes(fullData.id) }")
                span.icon(:title="data" :class="getStatusColor") &#9679;
</template>

<script>
import { get } from 'vuex-pathify'

export default {
    name: 'cellStatus',
    props: ['data', 'type', 'fullData'],
    computed: {
        openedSegments: get('activeSegments/openedSegments'),
        activeMenu: get('menu/activeMenu'),
        getStatusColor() {
            const { data } = this
            if (data === 'active') return 'green'
            else if (data === 'inactive') return 'red'
            else if (data === 'paused') return 'orange'
            return ''
        }
    },
}
</script>

Upvotes: 1

Views: 455

Answers (2)

tony19
tony19

Reputation: 138626

Create a computed property that returns the capitalized form of data:

export default {
  computed: {
    title() {
      return this.data?.length && this.data[0].toUpperCase() + this.data.slice(1)
    }
  }
}

And instead of data, bind the computed prop to the span's title attribute:

span.icon(:title="title" :class="getStatusColor") &#9679;
                    👆

demo

Upvotes: 1

jeremy-denis
jeremy-denis

Reputation: 6878

to capitalize only first letter of a text you can use the css selector :first-letter and text-transform: uppercase;

 .title:first-letter {
     text-transform: uppercase;
 }
<div class="title">my text</div>

Upvotes: 1

Related Questions