# popper-max-size-modifier

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

Latest version **0.2.0** (published 2020-04-18) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install popper-max-size-modifier
pnpm add popper-max-size-modifier
yarn add popper-max-size-modifier
bun add popper-max-size-modifier
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2020-04-18 |
| First published | 2020-03-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | atomiks |
| Maintainers | atomiks |

## Links

- npm: https://www.npmjs.com/package/popper-max-size-modifier
- npm.io page: https://npm.io/package/popper-max-size-modifier

## Recent versions

- 0.2.0 (latest) — 2020-04-18
- 0.1.2 — 2020-04-03
- 0.1.1 — 2020-03-20
- 0.1.0 — 2020-03-19

## README

# popper-max-size-modifier

A [Popper.js](https://popper.js.org) modifier to change the size of your popper
to fit it within the available viewport space.

## Installation

```bash
# 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

```js
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):

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

## Options

All
[`detectOverflow` options](https://popper.js.org/docs/v2/utils/detect-overflow/#options)
can be passed.

```js
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`](https://github.com/atomiks/popper.js/blob/master/src/modifiers/maxSize.js).

---
_Source: https://npm.io/package/popper-max-size-modifier · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
