InputGroupAddon.vue 969 B

123456789101112131415161718192021222324252627282930313233343536
  1. <script setup lang="ts">
  2. import type { HTMLAttributes } from "vue"
  3. import type { InputGroupVariants } from "."
  4. import { cn } from '@/Packages/Shadcn/Lib/utils'
  5. import { inputGroupAddonVariants } from "."
  6. const props = withDefaults(defineProps<{
  7. align?: InputGroupVariants["align"]
  8. class?: HTMLAttributes["class"]
  9. }>(), {
  10. align: "inline-start",
  11. })
  12. function handleInputGroupAddonClick(e: MouseEvent) {
  13. const currentTarget = e.currentTarget as HTMLElement | null
  14. const target = e.target as HTMLElement | null
  15. if (target && target.closest("button")) {
  16. return
  17. }
  18. if (currentTarget && currentTarget?.parentElement) {
  19. currentTarget.parentElement?.querySelector("input")?.focus()
  20. }
  21. }
  22. </script>
  23. <template>
  24. <div
  25. role="group"
  26. data-slot="input-group-addon"
  27. :data-align="props.align"
  28. :class="cn(inputGroupAddonVariants({ align: props.align }), props.class)"
  29. @click="handleInputGroupAddonClick"
  30. >
  31. <slot />
  32. </div>
  33. </template>