Skip to content

Commit

Permalink
feat: arrowOverflow prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Jan 15, 2022
1 parent 167a8b8 commit 0ed3801
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,22 @@ export default {
</template>
</div>

<div class="flex space-x-3 hover:bg-gray-50 p-2">
<span>Arrow overflow:</span>
<label
v-for="value of [undefined, true, false]"
:key="value"
class="flex items-center space-x-1"
>
<input
v-model="theme.config.arrowOverflow"
type="radio"
:value="value"
>
<span>{{ value != null ? value : '(inherit)' }}</span>
</label>
</div>

<div class="flex space-x-3 hover:bg-gray-50 p-2">
<span>Flip:</span>
<label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const emptyTheme = [
'html',
'loadingContent',
'arrowPadding',
'arrowOverflow',
'overflowPadding',
'preventOverflow',
'autoMinSize',
Expand Down
2 changes: 2 additions & 0 deletions packages/docs/src/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const config: FloatingVueConfig = {
overflowPadding: 0,
// Arrow padding (px)
arrowPadding: 0,
// Compute arrow overflow (useful to hide it)
arrowOverflow: true,
// Themes
themes: {
tooltip: {
Expand Down
41 changes: 24 additions & 17 deletions packages/floating-vue/src/components/Popper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ export default () => ({
default: defaultPropFactory('arrowPadding'),
},

arrowOverflow: {
type: Boolean,
default: defaultPropFactory('arrowOverflow'),
},

flip: {
type: Boolean,
default: defaultPropFactory('flip'),
Expand Down Expand Up @@ -456,23 +461,25 @@ export default () => ({
}))

// Arrow overflow
options.middleware.push({
name: 'arrowOverflow',
fn: ({ placement, rects, middlewareData }) => {
let overflow: boolean
const { centerOffset } = middlewareData.arrow
if (placement.startsWith('top') || placement.startsWith('bottom')) {
overflow = Math.abs(centerOffset) > rects.reference.width / 2
} else {
overflow = Math.abs(centerOffset) > rects.reference.height / 2
}
return {
data: {
overflow,
},
}
},
})
if (this.arrowOverflow) {
options.middleware.push({
name: 'arrowOverflow',
fn: ({ placement, rects, middlewareData }) => {
let overflow: boolean
const { centerOffset } = middlewareData.arrow
if (placement.startsWith('top') || placement.startsWith('bottom')) {
overflow = Math.abs(centerOffset) > rects.reference.width / 2
} else {
overflow = Math.abs(centerOffset) > rects.reference.height / 2
}
return {
data: {
overflow,
},
}
},
})
}

// Auto min size for the popper inner
if (this.autoMinSize) {
Expand Down
2 changes: 2 additions & 0 deletions packages/floating-vue/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const config: FloatingVueConfig = {
overflowPadding: 0,
// Arrow padding (px)
arrowPadding: 0,
// Compute arrow overflow (useful to hide it)
arrowOverflow: true,
// Themes
themes: {
tooltip: {
Expand Down

0 comments on commit 0ed3801

Please sign in to comment.