-
Notifications
You must be signed in to change notification settings - Fork 1.1k
AvatarGroup : add overflow slot for custom tooltip on hidden avatars #6369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v4
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <script setup lang="ts"> | ||
| const getOverflowTooltip = (hiddenCount: number) => `${hiddenCount} more teammates` | ||
| </script> | ||
|
|
||
| <template> | ||
| <UAvatarGroup :max="2"> | ||
| <UAvatar | ||
| src="https://github.com/benjamincanac.png" | ||
| alt="Benjamin Canac" | ||
| loading="lazy" | ||
| /> | ||
|
|
||
| <UAvatar | ||
| src="https://github.com/romhml.png" | ||
| alt="Romain Hamel" | ||
| loading="lazy" | ||
| /> | ||
|
|
||
| <UAvatar | ||
| src="https://github.com/noook.png" | ||
| alt="Neil Richter" | ||
| loading="lazy" | ||
| /> | ||
|
|
||
| <template #overflow="{ hiddenCount, avatarProps }"> | ||
| <UTooltip :text="getOverflowTooltip(hiddenCount)"> | ||
| <UAvatar v-bind="avatarProps" /> | ||
| </UTooltip> | ||
| </template> | ||
| </UAvatarGroup> | ||
| </template> | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -69,6 +69,12 @@ slots: | |||||
| :u-avatar{src="https://github.com/noook.png" alt="Neil Richter" loading="lazy"} | ||||||
| :: | ||||||
|
|
||||||
| ### Overflow tooltip | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the unreleased-feature badge to this new docs heading. This section documents a new slot API, so the heading should carry the Suggested docs fix-### Overflow tooltip
+### Overflow tooltip :badge{label="Soon" class="align-text-top"}As per coding guidelines, π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||
|
|
||||||
| Use the `overflow` slot to customize the `+X` avatar. The slot receives the hidden count and the default avatar props, so you can wrap the overflow avatar with a [Tooltip](/docs/components/tooltip) and provide either a static string or a helper function that derives the label from the count. | ||||||
|
|
||||||
| :component-example{name="avatar-group-overflow-tooltip-example"} | ||||||
|
|
||||||
| ## Examples | ||||||
|
|
||||||
| ### With tooltip | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ export interface AvatarGroupProps { | |
|
|
||
| export interface AvatarGroupSlots { | ||
| default?(props?: {}): VNode[] | ||
| overflow?(props: { hiddenCount: number, avatarProps: { text: string, class: any } }): VNode[] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expose the overflow slot marker through The fallback overflow avatar is still marked as Proposed fix- overflow?(props: { hiddenCount: number, avatarProps: { text: string, class: any } }): VNode[]
+ overflow?(props: { hiddenCount: number, avatarProps: { text: string, class: any, 'data-slot': string } }): VNode[] const overflowAvatarProps = computed(() => ({
text: `+${hiddenCount.value}`,
- class: ui.value.base({ class: uiProp.value?.base })
+ class: ui.value.base({ class: uiProp.value?.base }),
+ 'data-slot': 'overflow'
})) <slot v-if="hiddenCount > 0" name="overflow" :hidden-count="hiddenCount" :avatar-props="overflowAvatarProps">
- <UAvatar v-bind="overflowAvatarProps" data-slot="base" />
+ <UAvatar v-bind="overflowAvatarProps" />
</slot>As per coding guidelines, Also applies to: 94-108 π€ Prompt for AI Agents |
||
| } | ||
| </script> | ||
|
|
||
|
|
@@ -90,14 +91,21 @@ const hiddenCount = computed(() => { | |
| return children.value.length - visibleAvatars.value.length | ||
| }) | ||
|
|
||
| const overflowAvatarProps = computed(() => ({ | ||
| text: `+${hiddenCount.value}`, | ||
| class: ui.value.base({ class: uiProp.value?.base }) | ||
| })) | ||
|
|
||
| provide(avatarGroupInjectionKey, computed(() => ({ | ||
| size: props.size | ||
| }))) | ||
| </script> | ||
|
|
||
| <template> | ||
| <Primitive :as="as" data-slot="root" :class="ui.root({ class: [uiProp?.root, props.class] })"> | ||
| <UAvatar v-if="hiddenCount > 0" :text="`+${hiddenCount}`" data-slot="base" :class="ui.base({ class: uiProp?.base })" /> | ||
| <slot v-if="hiddenCount > 0" name="overflow" :hidden-count="hiddenCount" :avatar-props="overflowAvatarProps"> | ||
| <UAvatar v-bind="overflowAvatarProps" data-slot="base" /> | ||
| </slot> | ||
| <component :is="avatar" v-for="(avatar, count) in visibleAvatars" :key="count" data-slot="base" :class="ui.base({ class: uiProp?.base })" /> | ||
| </Primitive> | ||
| </template> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pluralize the tooltip label for the single-hidden-avatar case.
With the current example data, this renders
1 more teammates.Suggested copy fix
π Committable suggestion
π€ Prompt for AI Agents