Files
headlessui/packages/@headlessui-vue/src/hooks/use-text-value.ts
T
Robin Malfait 76dd10ea55 Sort imports automatically (#2741)
* add `prettier-plugin-organize-imports` and `prettier-plugin-tailwindcss`

* format

* bump Tailwind CSS

* format playgrounds using updated Tailwind CSS and Prettier plugins

* use import syntax
2023-09-11 18:36:30 +02:00

26 lines
634 B
TypeScript

import { ref, Ref } from 'vue'
import { dom } from '../utils/dom'
import { getTextValue } from '../utils/get-text-value'
export function useTextValue(element: Ref<HTMLElement | null>) {
let cacheKey = ref<string>('')
let cacheValue = ref<string>('')
return () => {
let el = dom(element)
if (!el) return ''
// Check for a cached version
let currentKey = el.innerText
if (cacheKey.value === currentKey) {
return cacheValue.value
}
// Calculate the value
let value = getTextValue(el).trim().toLowerCase()
cacheKey.value = currentKey
cacheValue.value = value
return value
}
}