-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(component): lab component ChipSet
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
packages/vue-components/components/labs/chip-set/ChipSet.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<template> | ||
<div data-am-chip-set v-bind="$attrs" ref="setRef" @keydown="handleKeydown"> | ||
<slot></slot> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed, ref } from 'vue'; | ||
const setRef = ref<HTMLElement | null>(null) | ||
const chips = computed(() => { | ||
if(setRef.value === null || setRef.value?.childElementCount === 0) return [] | ||
const children = [...setRef.value.children].filter(e => e.getAttribute('data-am-chip') || e.getAttribute('data-is-chip')) | ||
return children | ||
}) | ||
const handleKeydown = (e: KeyboardEvent) => { | ||
const isLeft = e.key === 'ArrowLeft'; | ||
const isRight = e.key === 'ArrowRight'; | ||
const isHome = e.key === 'Home'; | ||
const isEnd = e.key === 'End'; | ||
if (!isLeft && !isRight && !isHome && !isEnd) { | ||
return; | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
</style> |