Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cibernox/ember-basic-dropdown
The basic dropdown you ember app needs
https://github.com/cibernox/ember-basic-dropdown
addon dropdown ember
Last synced: about 23 hours ago
JSON representation
The basic dropdown you ember app needs
- Host: GitHub
- URL: https://github.com/cibernox/ember-basic-dropdown
- Owner: cibernox
- License: other
- Created: 2015-10-06T17:25:15.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-09-21T10:32:06.000Z (4 months ago)
- Last Synced: 2024-10-29T15:24:11.990Z (3 months ago)
- Topics: addon, dropdown, ember
- Language: JavaScript
- Homepage: http://www.ember-basic-dropdown.com
- Size: 8.07 MB
- Stars: 157
- Watchers: 5
- Forks: 183
- Open Issues: 29
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Ember-basic-dropdown
[![Build Status](https://github.com/cibernox/ember-basic-dropdown/actions/workflows/ci.yml/badge.svg?branch=master)](https://travis-ci.org/cibernox/ember-basic-dropdown)
This is a very minimal dropdown. That means that it is agnostic about what it is going to contain.
It is intended to be a building block for more complex components but is perfectly usable. It is
by example the addon on which [ember-power-select](https://www.ember-power-select.com)
or `ember-paper`'s [menu component](http://miguelcobain.github.io/ember-paper/#/components/menu) are built upon.### Compatibility
* Ember.js v3.28 or above
* Ember CLI v3.28 or aboveVersions 1.X require Ember 2.16 or greater
Version 2.X requires Ember 3.13 or greater
Version 3.X - 6.X requires Ember 3.24 or greater
Version 7.X - 8.X requires Ember 3.28 or greater
### Installation
```
ember install ember-basic-dropdown
```For more installation details see [documentation](https://ember-basic-dropdown.com/docs/installation)
### Usage
This component leverages contextual components for its API:
```hbs
Click me
Content of the trigger```
The yielded `dropdown` object is the public API of the component, and contains
properties and actions that you can use to control the component.```js
{
uniqueId: ,
isOpen: ,
disabled: ,
actions: {
open: ,
close: ,
toggle: ,
reposition:
}
}
```Check the full documentation with live examples in http://ember-basic-dropdown.com
### Features
#### Renders on the body or in place
By default this component will render the dropdown in the body using `#-in-element` and absolutely
position it to place it in the proper coordinates.You can opt out to this behavior by passing `renderInPlace=true`. That will add the dropdown just
below the trigger.#### Close automatically when clicking outside the component
You don't need to care about adding or removing events, it does that for you.
You can make the dropdown content standout a little more by adding `overlay=true` to the content options, see example below. This will add a semi transparent overlay covering the whole screen. Also this will stop bubbling the click/touch event which closed the dropdown.
```hbs
Click me!
{{! here! }}
content!
```
NOTE: If for some reason clicking outside a dropdown doesn't work, you might want to make sure the `` spans the entire viewport. Adding a css rule like `body {min-height: 100vh;}` would do the trick. It ensures that wherever you click on the page, it will close the dropdown.
#### Close automatically when clicking inside the component
If you'd like the dropdown to close itself after a user clicks on it, you can use `dd.actions.close` from our public API.
```hbs
Click me!
{{yield dd}}
```
#### Keyboard and touchscreen support
The trigger of the component is focusable by default, and when focused can be triggered using `Enter` or `Space`.
It also listen to touch events so it works in mobile.#### Easy to extend
The components provide hooks like `onFocus`, `onBlur`, `onKeydown`, `onMouseEnter` and more so
you can do pretty much anything you want.#### Easy to animate.
You can animate it, in an out, with just CSS3 animations.
Check the example in the [Ember Power Select documentation](http://www.ember-power-select.com/cookbook/css-animations)#### Intelligent and customizable positioning
This component is smart about where to position the dropdown. It will detect the best place to render
it based on the space around the trigger, and also will take care of reposition if if the screen is
resized, scrolled, the device changes it orientation or the content of the dropdown changes.You can force the component to be fixed in one position by passing `verticalPosition = above | below` and/or `horizontalPosition = right | center | left`.
If even that doesn't match your preferences and you feel brave enough, you can roll your own positioning logic if you pass a `calculatePosition`
function. It's signature is:```
calculatePosition(trigger, dropdown, { previousHorizontalPosition, horizontalPosition, previousVerticalPosition, verticalPosition, matchTriggerWidth })
```The return value must be an object with this interface: `{ horizontalPosition, verticalPosition, style }` where
where `horizontalPosition` is a string (`"right" | "center" | "left"`), `verticalPosition` is also a string
(`"above" | "below"`) and `style` is an object with CSS properties, typically `top` and `left`/`right`.#### Test helpers
It has a handy collection of test helpers to make interaction with the component seamless in your
test suite.### Providing an Ember Twiddle
If you want to provide an [Ember Twiddle](https://www.ember-twiddle.com) with an issue/reproduction **you need to add the following to the end of your template**:
`
`Since `Ember Twiddle` does not run `EmberCLI's` hooks this `div` won't be added to the application and it's required (There's an issue in [Ember Twiddle](https://github.com/joostdevries/twiddle-backend/issues/35) tracking this).
In order to create the Ember Twiddle you'll also need to add a reference to `ember-basic-dropdown: version` in the `addons` section of `twiddle.json`