Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 13x 9x 9x 9x 9x 13x 9x 1x 1x 1x | <template>
<div ref="root">
<slot :items="visibleItems" />
<div v-if="visibleItems.length < items.length" class="mt-10 flex justify-center">
<UButton
variant="outline"
color="neutral"
:label
trailing-icon="i-lucide-chevron-down"
@click="showAll"
/>
</div>
</div>
</template>
<script setup lang="ts" generic="T">
interface Props {
items: T[];
limit: number;
label: string;
}
const props = defineProps<Props>();
const expanded = ref<boolean>(false);
const root = useTemplateRef("root");
const visibleItems = computed<T[]>(() =>
expanded.value ? props.items : props.items.slice(0, props.limit),
);
// The button unmounts as it is pressed, so focus moves to the first item it revealed
const showAll = async (): Promise<void> => {
expanded.value = true;
await nextTick();
// Assumes every revealed item renders exactly one link
root.value?.querySelectorAll("a")[props.limit]?.focus();
};
</script>
|