Skip to content

Instantly share code, notes, and snippets.

@vivekascoder
Created June 7, 2021 11:01
Show Gist options
  • Save vivekascoder/8064f2aab3c30184757781ba32d601d8 to your computer and use it in GitHub Desktop.
Save vivekascoder/8064f2aab3c30184757781ba32d601d8 to your computer and use it in GitHub Desktop.
<template>
<ul class="w-item-picker__list">
<li
v-for="item in value"
:key="item.id"
class="w-item-picker__item">
<button class="btn">
<span
:ref="`item${item.id}`"
@mouseover="mouseOver(item.id, item.name)"
>{{ item.name }}</span>
</button>
</li>
</ul>
</template>
<script>
export default {
name: 'ItemList',
mounted() {
// console.log(el.clientWidth < el.scrollWidth)
},
methods: {
mouseOver(id, name) {
let el = this.$refs[`item${id}`]
if (el.clientWidth < el.scrollWidth) {
el.setAttribute('title', name)
}
},
isOverflow(id) {
// let el = this.$refs[`tip${id}`]
// return el.clientWidth < el.scrollWidth
// return true
}
},
computed: {
},
props: {
title: {
type: Object,
default: {
isOverflow: false,
value: ''
}
},
value: {
type: Array, default: () => ([
{
id: 1,
name: 'v1'
},
{
id: 2,
name: 'tomato'
},
{
id: 3,
name: 'cucumber'
},
{
id: 4,
name: 'very long text with more than 20 char'
}
]) }
}
};
</script>
<style lang="scss">
.w-item-picker__list {
list-style: none;
margin: 0;
padding: 0;
.w-item-picker__item {
.btn {
position: relative;
border-radius: 50px;
border: none;
padding: 4px 12px;
margin: 4px 8px;
color: black;
max-width: 210px;
span {
display: block;
overflow: hidden;
text-overflow: ellipsis;
max-width: 200px;
white-space: nowrap;
}
}
}
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment