Socket
Socket
Sign inDemoInstall

popper-max-size-modifier

Package Overview
Dependencies
1
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    popper-max-size-modifier

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


Version published
Weekly downloads
89K
increased by8.14%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

popper-max-size-modifier

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

Usage

import {createPopper} from '@popperjs/core';
import maxSize from 'popper-max-size-modifier';

// Create your own apply modifier that mutates the popper element's styles:
const applyMaxSize = {
  name: 'applyMaxSize',
  enabled: true,
  phase: 'write',
  requires: ['maxSize'],
  fn({state}) {
    // The `maxSize` modifier provides this data
    const {width, height} = state.modifiersData.maxSize;

    state.elements.popper.style.maxWidth = `${width}px`;
    state.elements.popper.style.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
state.elements.popper.style.maxWidth = `${Math.max(100, width)}px`;
state.elements.popper.style.maxHeight = `${Math.max(100, height)}px`;

FAQs

Last updated on 19 Mar 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc