Skip to content

flip

A middleware that flips the floating element to an alternative placement to keep it in view.

Signature

ts
function flip(options?: FlipOptions): Middleware

Options

ts
interface FlipOptions {
  mainAxis?: boolean
  crossAxis?: boolean | 'alignment'
  fallbackAxisSideDirection?: 'none' | 'start' | 'end'
  flipAlignment?: boolean
  fallbackPlacements?: Array<Placement>
  fallbackStrategy?: 'bestFit' | 'initialPlacement'
}
OptionTypeDefaultDescription
mainAxisbooleantrueWhether to flip on the main axis
crossAxisboolean | 'alignment'trueWhether to flip on the cross axis
fallbackAxisSideDirection'none' | 'start' | 'end''none'Direction to try when both axes fail
flipAlignmentbooleantrueWhether to flip alignment (e.g., start to end)
fallbackPlacementsArray<Placement>[]Custom fallback placements to try
fallbackStrategy'bestFit' | 'initialPlacement''bestFit'Strategy when all placements fail

Examples

Basic Usage

vue
<script setup>
import { useFloating, flip } from 'v-float'

const context = useFloating(anchorEl, floatingEl, {
  middleware: [flip()]
})
</script>

Custom Fallback Placements

vue
<script setup>
import { useFloating, flip } from 'v-float'

const context = useFloating(anchorEl, floatingEl, {
  middleware: [
    flip({
      fallbackPlacements: ['top', 'right', 'bottom']
    })
  ]
})
</script>

See Also

  • autoPlacement - Alternative middleware for automatic placement selection
  • shift - Shifts the floating element to keep it in view
  • offset - Offsets the floating element from its anchor

Released under the MIT License.