Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ngx-popperjs

tonysamperi60.1kMIT17.0.1TypeScript support: included

ngx-popperjs is an Angular wrapper for @popperjs

Angular 8+, ngx-popperjs, popper Angular, Angular 15, popper.js

readme

ngx-popperjs

npm npm MIT licensed Build state Size Rate this package

ngx-popperjs is an angular wrapper for the FloatingUI library (v ^1.5.3).

VERY IMPORTANT READ THIS

With v17 ngx-popperjs won't get any updates. That's because from v17 it's not actually using popper.js anymore.

I developed ngx-float-ui and released v17 at the same time of this. My suggestion is to migrate to that one. In 6 months from the release, this version will be marked as deprecated. Since the new library isn't affected by the "Chrome 110 bug" I would suggest to migrate earlier versions as well. If you open an issue on ngx-float-ui asking for a certain version (or search for an open issue for that version and leave a thumb), I will publish earlier versions as well.

NOW USING FLOATING UI - UPGRADING TO v17

If you used previous versions of ngx-popperjs, you'll now that it wrapped popper.js initially. Since Floating UI is the future version of Popper.js and since latest happenings with recent Chrome updates breaking ngx-popperjs, I decided to move to the newer technology.

What impacts does it have for the library?

Well on a graphic perspective, none. You will be able to use the v17 without changing any stylings.

The only deprecation is in the NgxPopperjsOptions which now doesn't provide the modifiers. The reason is that you can't now pass modifiers like you did in Popper.js. It didn't seem like a huge change, since in this library modifiers should be mostly (but let me know with an issue) for preventing the popper flipping. Maybe if we see that it can be useful we can pass an override for the middleware.

I simply added a new attribute, popperFlip, that you can set to false, in order to prevent the flipping (default true).

Check NgxPopperjs official page to stay up to date!

Premise

The goal of this library is to take Mr Frankel's ngx-popper and update the compatibility for more recent versions of Angular. Since the old library is compatible with Angular 7 and earlier, I started with Angular 8. If you need to work with an older version of Angular (5 to 7), please refer to Mr Frankel's ngx-popper.

From v15.2.0:

Since many complained about using the NgxPopperjsPlacements enum, I added a version of the popper directive which accepts a plain string as placement! Now you can use it with all the options of the classic popper, but you'll have to use:

popperLoose instead of popper

and

popperLoosePlacement instead of popperPlacement

Installation

node and npm are required to run this package.

  1. Use npm/yarn to install the package:

    $ npm install @floating-ui/dom ngx-popperjs --save

    Or

     $ yarn add @floating-ui/dom --save
     $ yarn add ngx-popperjs --save 
  2. You simply add into your module NgxPopperjsModule:

    import {NgxPopperjsModule} from 'ngx-popperjs';
    
    @NgModule({
    // ...
    imports: [
      // ...
      NgxPopperjsModule
    ]
    })

Optionally you can include in your styles.css / styles.css one of the prebuilt themes:

  • @import node_modules/ngx-popperjs/css/theme-dark.css
  • @import node_modules/css/theme-white.css

  • @use ngx-popperjs/scss/theme as popperBaseTheme

  • @use ngx-popperjs/scss/theme-dark as popperDarkTheme
  • @use ngx-popperjs/scss/theme-white popperWhiteTheme

or easily create your own theme using the @mixin:

@use "ngx-popperjs/scss/theme" as popperBaseTheme;

body {
    @include popperjs.ngx-popperjs-theme($background-color, $text-color, $max-width, $z-index);
}
  1. Add to view:

    <popper-content #popper1Content>
        <p class="bold">Popper on bottom</p>
    </popper-content>
    <div [popper]="popper1Content"
         [popperShowOnStart]="true"
         [popperTrigger]="'click'"
         popperHideOnClickOutside
         [popperHideOnScroll]="true"
         [popperPlacement]="'bottom'">
        <p class="bold">Hey!</p>
        <p class="thin">Choose where to put your popper!</p>         
    </div>
  2. As text:

       <div popper="As text"
            [popperTrigger]="'hover'"
            [popperPlacement]="'bottom'"
            (popperOnShown)="onShown($event)">
         <p class="bold">Pop</p>
         <p class="thin">on the bottom</p>
       </div>
        <div popper="{{someTextProperty}}"
             [popperTrigger]="'hover'"
             [popperPlacement]="'bottom'"
             [popperStyles]="{'background-color: 'blue''}"
             (popperOnShown)="onShown($event)">
          <p class="bold">Pop</p>
          <p class="thin">on the bottom</p>
        </div>
    1. Position fixed, breaking overflow:

        <div popper="As text"
             [popperTrigger]="'hover'"
             [popperPlacement]="'bottom'"
             [popperPositionFixed]="true"
             (popperOnShown)="onShown($event)">
        </div>
    2. Specific target:

      <div class="example">
       <div #popperTargetElement></div>
       <div popper="As text"
            popperTrigger="hover"
            popperPlacement="bottom"
            [popperTarget]="popperTargetElement.nativeElement"
            (popperOnShown)="onShown($event)">
       </div>
  3. hide/show programmatically:

    <div [popper]="tooltipcontent"
         popperTrigger="hover"
         popperPlacement="bottom"
         [popperApplyClass]="'popperSpecialStyle'">
         <p class="bold">Pop</p>
         <p class="thin">on the bottom</p>
       </div>
       <popper-content #tooltipcontent>
         <div>
           <p>This is a tooltip with text</p>
           <span (click)="tooltipcontent.hide()">Close</span>
         </div>
       </popper-content>
  4. Attributes map:

    | Option | Type | Default | Description | |:-------------------------|:------------------|:----------|:---------------------------------------------------------------------------------------| | popperDisableAnimation | boolean | false | Disable the default animation on show/hide | | popperDisableStyle | boolean | false | Disable the default styling | | popperDisabled | boolean | false | Disable the popper, ignore all events | | popperDelay | number | 0 | Delay time until popper it shown | | popperTimeout | number | 0 | Set delay before the popper is hidden | | popperTimeoutAfterShow | number | 0 | Set a time on which the popper will be hidden after it is shown | | popperPlacement | Placement(string) | auto | The placement to show the popper relative to the reference element | | popperTarget | HtmlElement | auto | Specify a different reference element other the the one hosting the directive | | popperBoundaries | string(selector) | undefined | Specify a selector to serve as the boundaries of the element | | popperShowOnStart | boolean | false | Popper default to show | | popperTrigger | Trigger(string) | click | Trigger/Event on which to show/hide the popper | | popperPositionFixed | boolean | false | Set the popper element to use position: fixed | | popperAppendTo | string | undefined | append The popper-content element to a given selector, if multiple will apply to first | | popperPreventOverflow | boolean | undefined | Prevent the popper from being positioned outside the boundary | | popperHideOnClickOutside | boolean | true | Popper will hide on a click outside | | popperHideOnScroll | boolean | false | Popper will hide on scroll | | popperHideOnMouseLeave | boolean | false | Popper will hide on mouse leave | | popperApplyClass | string | undefined | list of comma separated class to apply on ngpx__container | | popperStyles | Object | undefined | Apply the styles object, aligned with ngStyles | | popperApplyArrowClass | string | undefined | list of comma separated class to apply on ngpx__arrow | | popperOnShown | EventEmitter<> | $event | Event handler when popper is shown | | popperOnHidden | EventEmitter<> | $event | Event handler when popper is hidden | | popperOnUpdate | EventEmitter<> | $event | Event handler when popper is updated | | popperAriaDescribeBy | string | undefined | Define value for aria-describeby attribute | | popperAriaRole | string | popper | Define value for aria-role attribute | | popperFlip | boolean | true | Enable or disable the flipping |

  1. Override defaults:

    ngx-popperjs comes with a few default properties you can override in default to effect all instances These are overridden by any child attributes. `JavaScript NgModule({ imports: [ BrowserModule, FormsModule, NgxPopperjsModule.forRoot({placement: NgxPopperjsPlacements.TOP})], declarations: [AppComponent], providers: [], bootstrap: [AppComponent]

});


   | Options                  | Type              | Default   |
   |:-------------------      |:----------------  |:--------- |
   | showDelay                | number            | 0         |
   | disableAnimation         | boolean           | false     |
   | disableDefaultStyling    | boolean           | false     |
   | placement                | Placement(string) | auto      |
   | boundariesElement        | string(selector)  | undefined |
   | trigger                  | Trigger(string)   | hover     |
   | positionFixed            | boolean           | false     |
   | hideOnClickOutside       | boolean           | true      |
   | hideOnMouseLeave         | boolean           | false     |
   | hideOnScroll             | boolean           | false     |
   | applyClass               | string            | undefined |
   | styles                   | Object            | undefined |
   | applyArrowClass          | string            | undefined |
   | ariaDescribeBy           | string            | undefined |
   | ariaRole                 | string            | undefined |
   | appendTo                 | string            | undefined |
   | preventOverflow          | boolean           | undefined |

10. popperPlacement:

  | 'top'
  | 'bottom'
  | 'left'
  | 'right'
  | 'top-start'
  | 'bottom-start'
  | 'left-start'
  | 'right-start'
  | 'top-end'
  | 'bottom-end'
  | 'left-end'
  | 'right-end'
  | 'auto'
  | 'auto-start'
  | 'auto-end'
  | Function

11. popperTrigger:

  | 'click'
  | 'mousedown'
  | 'hover'
  | 'none'


### Demo site with sample codes
<a href="https://tonysamperi.github.io/ngx-popperjs/">Demo of ngx-popperjs</a>

### Contribute
  You can only **report bugs**. Every other issue will be deleted right away.

```terminal
  $ npm install
  $ npm run start  //run example

License

This project is licensed under the MIT License - see the LICENSE file for details

Thanks to

MrFrankel for setting up ngx-popper and maintaining till v 7.0.0.

changelog

17.0.1

  • Jetbrains no longer supporting :(

17.0.0

  • Update for Angular 17! 🎉

16.0.6

  • The final fix of the "Chrome 115.0.5790.102 bug" reverting the original behaviour
  • Refine tests

16.0.5

  • Removed debug log

16.0.4

  • Fixed stylings conflict when using popperInlineStyles (fixes #56)

16.0.3

  • Fixed appearance of border when hidden (fixes #54)

16.0.2

  • Fixed position issues if shown on click + hover w/ Chrome 115.0.5790.102 (closes #52)

16.0.1

  • Add type-safe popperLooseTrigger in popperLoose
  • Add type safety in popperLoosePlacement (thanks k290)

16.0.0

  • Update for Angular 16! 🎉

15.2.0

  • Fix hideOnScroll
  • Add popperLoose for people who don't want to use the NgxPopperjsPlacements enum!

15.1.0

  • General improvements

15.0.4

  • Remove conflicting @forward instructions
  • Added configurable config

15.0.3

  • Added missing sass exports in package

15.0.2

  • Exposed sass _index for @use

15.0.1

  • Fixed peerDependencies
  • Removed protractor
  • Fixed tests and added new tests 🎉
  • Added tests to github actions 🎉

15.0.0

  • Update for Angular 15! 🎉

14.1.2

  • Added rxjs to peerDependencies in build package

14.1.1

  • Updated latest patch for @popperjs/core

14.1.0

  • Moved @popperjs/core to dependencies to get it installed automatically upon installing ngx-popperjs

14.0.2

  • Angular 14 now allows to dynamically append components without using any factory (closes #29)
  • Fixed tsconfig

14.0.1

  • Added missing peer dep

14.0.0

  • Update for Angular 14! 🎉

13.2.2

  • Added missing peer dep (closes #26)

13.2.1

  • Updated core dep

13.2.0

  • General refactor of dynamic component handling
  • Refactored events using rxjs instead of renderer: should lead to performance improvement

    13.1.0

  • Added exportAs in NgxPopperjsContentComponent to allow access value, such as id (fix #21)

13.0.1

  • Removed listener for touchend, causing popper to close on mobile although it shouldn't (fix #18)

13.0.0

  • Update for Angular 13! 🎉
  • Removed polyfills from demo app
  • Misc

12.2.1

  • Fixed docs (default popperTrigger is "click" since v8)
  • Removed old prop "showTrigger" probably inherit from a previous version of popper.js

12.2.0

  • Fixed isssue with popperPlacement passed though forRoot (#14)
  • Added exportAs "popper" on NgxPopperJsDirective (#15)

12.1.2

  • Changed peer dependencies to support latest minor, thanks to @BrycenDavisSH

12.1.1

  • Refactor of duplicated code
  • Updating popper on preventOverflow input change

12.1.0

  • Update for Angular 12.1.x! 🎉

12.0.0

  • Update for Angular 12.0.x! 🎉

11.0.0

  • Update for Angular 11! 🎉

10.0.4

  • Updated postinstall validation

10.0.2

  • Added postinstall validation

10.0.1

  • Fixed use of "append" breaking IE11 (and probably lower)
  • Added typings for prismjs
  • Added polyfill for prismjs (demo app)
  • Added support for IE10-11 (demo app)

10.0.0

  • Upgrade for Angular 10

9.0.7

  • Updated postinstall validation

9.0.4

  • Added postinstall validation

9.0.1

  • Fix peerDependencies

9.0.0

  • Removed router which was actually pointless (only for demo, but still unused)
  • Upgrade for Angular 9

8.0.6

  • Fix arrow color when using NgxPopperjsOptions.style.backgroundColor to set default popper color
  • Made NgxPopperjsContentComponent extensible (protected members)
  • Misc and refactor

8.0.5

  • Allowing importing without using the forRoot to use defaults automatically

8.0.4

  • Handled void popperContentRef
  • Improved performance

8.0.3

  • Using InjectionToken to handle defaults, preventing using forRoot on every module importing NgxPopperJsModule

8.0.2

  • Fixed @Input popperModifiers as now is array
  • Fixed array types convention

8.0.1

  • ReadMe improved

8.0.0