Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

popper-max-size-modifier

0.2.0 • Public • Published

popper-max-size-modifier

A Popper.js modifier to change the size of your popper to fit it within the available viewport space.

Installation

# With npm 
npm i popper-max-size-modifier
 
# With Yarn 
yarn add popper-max-size-modifier

Demo

https://codesandbox.io/s/great-tesla-3roz7

Usage

import {createPopper} from '@popperjs/core';
import maxSize from 'popper-max-size-modifier';
 
// Create your own apply modifier that adds the styles to the state
const applyMaxSize = {
  name: 'applyMaxSize',
  enabled: true,
  phase: 'beforeWrite',
  requires: ['maxSize'],
  fn({state}) {
    // The `maxSize` modifier provides this data
    const {width, height} = state.modifiersData.maxSize;
 
    state.styles.popper = {
      ...state.styles.popper,
      maxWidth: `${width}px`,
      maxHeight: `${height}px`
    };
  }
};
 
createPopper(reference, popper, {
  modifiers: [maxSize, applyMaxSize]
});

Sometimes you may want the flip modifier to take precedence in cases where the maxSize modifier will make the popper too small (e.g. a minimum acceptable size):

// Minimum acceptable size is 100px
`${Math.max(100, width)}px`;
`${Math.max(100, height)}px`;

Options

All detectOverflow options can be passed.

createPopper(reference, popper, {
  modifiers: [
    {
      ...maxSize,
      options: {
        boundary: customBoundaryElement,
        padding: 20
      }
    },
    applyMaxSize
  ]
});

Contributing

The source is located in the root package at src/modifiers/maxSize.js.

Keywords

none

Install

npm i popper-max-size-modifier

DownloadsWeekly Downloads

17,640

Version

0.2.0

License

MIT

Unpacked Size

5.74 kB

Total Files

6

Last publish

Collaborators

  • avatar