Skip to content

Commit 82ce0fd

Browse files
committed
feat(CPopover, CTooltip): add fallbackPlacements property to allow specify the desired order of fallback placements
1 parent fe0bf3a commit 82ce0fd

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

packages/coreui-vue/src/components/popover/CPopover.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defineComponent, h, PropType, ref, RendererElement, Teleport, Transition } from 'vue'
22
import { createPopper, Placement } from '@popperjs/core'
33

4+
import type { Placements } from '../../types'
45
import { executeAfterTransition } from '../../utils/transition'
56
import { getRTLPlacement } from '../../utils'
67

@@ -11,6 +12,24 @@ const CPopover = defineComponent({
1112
* Content for your component. If you want to pass non-string value please use dedicated slot `<template #content>...</template>`
1213
*/
1314
content: String,
15+
/**
16+
* Specify the desired order of fallback placements by providing a list of placements as an array. The placements should be prioritized based on preference.
17+
*
18+
* @since 4.9.0-beta.2
19+
*/
20+
fallbackPlacements: {
21+
type: [String, Array] as PropType<Placements | Placements[]>,
22+
default: () => ['top', 'right', 'bottom', 'left'],
23+
validator: (value: Placements | Placements[]) => {
24+
if (typeof value === 'string') {
25+
return ['top', 'right', 'bottom', 'left'].includes(value)
26+
}
27+
if (Array.isArray(value)) {
28+
return value.every((e) => ['top', 'right', 'bottom', 'left'].includes(e))
29+
}
30+
return false
31+
},
32+
},
1433
/**
1534
* Offset of the popover relative to its target.
1635
*/
@@ -103,6 +122,12 @@ const CPopover = defineComponent({
103122
element: '.popover-arrow',
104123
},
105124
},
125+
{
126+
name: 'flip',
127+
options: {
128+
fallbackPlacements: props.fallbackPlacements,
129+
},
130+
},
106131
{
107132
name: 'offset',
108133
options: {

packages/coreui-vue/src/components/tooltip/CTooltip.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defineComponent, h, PropType, ref, RendererElement, Teleport, Transition } from 'vue'
22
import { createPopper, Placement } from '@popperjs/core'
33

4+
import type { Placements } from '../../types'
45
import { executeAfterTransition } from '../../utils/transition'
56
import { getRTLPlacement } from '../../utils'
67

@@ -11,6 +12,24 @@ const CTooltip = defineComponent({
1112
* Content for your component. If you want to pass non-string value please use dedicated slot `<template #content>...</template>`
1213
*/
1314
content: String,
15+
/**
16+
* Specify the desired order of fallback placements by providing a list of placements as an array. The placements should be prioritized based on preference.
17+
*
18+
* @since 4.9.0-beta.2
19+
*/
20+
fallbackPlacements: {
21+
type: [String, Array] as PropType<Placements | Placements[]>,
22+
default: () => ['top', 'right', 'bottom', 'left'],
23+
validator: (value: Placements | Placements[]) => {
24+
if (typeof value === 'string') {
25+
return ['top', 'right', 'bottom', 'left'].includes(value)
26+
}
27+
if (Array.isArray(value)) {
28+
return value.every((e) => ['top', 'right', 'bottom', 'left'].includes(e))
29+
}
30+
return false
31+
},
32+
},
1433
/**
1534
* Offset of the tooltip relative to its target.
1635
*/
@@ -99,6 +118,12 @@ const CTooltip = defineComponent({
99118
element: '.tooltip-arrow',
100119
},
101120
},
121+
{
122+
name: 'flip',
123+
options: {
124+
fallbackPlacements: props.fallbackPlacements,
125+
},
126+
},
102127
{
103128
name: 'offset',
104129
options: {

packages/coreui-vue/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export type Placements =
2727
| 'left-start'
2828
| 'left'
2929
| 'left-end'
30-
| undefined
30+
| string
3131

3232
export type Shapes =
3333
| 'rounded'

0 commit comments

Comments
 (0)