• Stars
    star
    148
  • Rank 249,983 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The basic dropdown you ember app needs

Ember-basic-dropdown

Build Status

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 or ember-paper's menu component are built upon.

Compatibility

Version 3.X requires Ember 3.24 or greater Version 2.X requires Ember 3.13 or greater Versions 1.X require Ember 2.16 or greater

Installation

ember install ember-basic-dropdown

If you are using this addon in an application that uses ember-cli-sass, you need to import the styles explicitly.

Add to your app.scss this line:

@import 'ember-basic-dropdown';

If you are using ember-power-select you don't need any of those steps because you already have this addon :D

Usage

This component leverages contextual components for its API:

<BasicDropdown as |dd|>
  <dd.Trigger>Click me</dd.Trigger>
  <dd.Content>Content of the trigger</dd.Content>
</BasicDropdown>

The yielded dropdown object is the public API of the component, and contains properties and actions that you can use to control the component.

{
  uniqueId: <string>,
  isOpen: <boolean>,
  disabled: <boolean>,
  actions: {
    open: <action>,
    close: <action>,
    toggle: <action>,
    reposition: <action>
  }
}

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.

<BasicDropdown as |dd|>
  <dd.Trigger>Click me!</dd.Trigger>
  <dd.Content @overlay={{true}}>
    {{! here! }}
    content!
  </dd.Content>
</BasicDropdown>

NOTE: If for some reason clicking outside a dropdown doesn't work, you might want to make sure the <body> 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.

<BasicDropdown as |dd|>
  <dd.Trigger>Click me!</dd.Trigger>
  <dd.Content>
    <div {{action dd.actions.close}}>
      {{yield dd}}
    </div>
  </dd.Content>
</BasicDropdown>

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

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 with an issue/reproduction you need to add the following to the end of your template: <div id="ember-basic-dropdown-wormhole"></div>

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 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

More Repositories

1

ember-power-select

The extensible select component built for ember.
JavaScript
540
star
2

ember-cpm

ComputedProperty Macros for Ember
JavaScript
275
star
3

svelte-intl-precompile

I18n library for Svelte.js that analyzes your keys at build time for max performance and minimal footprint
JavaScript
258
star
4

ember-power-calendar

Powerful and customizable calendar component for Ember
JavaScript
207
star
5

ember-native-dom-helpers

Test helpers for your integration tests that fire native events
JavaScript
186
star
6

svelte-media

Svelte.js util to easily observe media queries as a reactive store
TypeScript
58
star
7

ember-cli-yuidoc

EmberCLI addon for generate documentation from YUIDoc coments
JavaScript
55
star
8

ember-power-datepicker

An extensible datepicker for Ember
JavaScript
50
star
9

ember-power-select-with-create

Ember-power-select addon with an `Add ${term}` option in the first position
JavaScript
50
star
10

ember-ast-helpers

Utility belt to level-up your Ember AST transforms
TypeScript
40
star
11

ember-text-measurer

Simple Ember Service to measure the width of a string in a performant way
JavaScript
38
star
12

ember-power-select-typeahead

Typeahead component built on top of ember-power-select
JavaScript
36
star
13

storyteller

Storyteller application built with Exilir and Dynamo. Is a concurrent storyteller.
Elixir
34
star
14

rubytapas_downloader

Simple ruby script that downloads the latest rubytapas episodes.
Ruby
26
star
15

mobile-patterns

Showcase of mobile UI patterns implemented in Ember.js
JavaScript
21
star
16

ember-hash-helper-polyfill

Polyfill for the new Ember hash helper
JavaScript
15
star
17

precompile-intl-runtime

Runtime helpers to be used in translations precompiled by babel-plugin-precompile-intl
TypeScript
10
star
18

ember-power-select-with-fallback

Ember Power Select that fallbacks to a native select when certain criteria are met
JavaScript
10
star
19

rollup-plugin-precompile-intl

Rollup plugin to precompile translations in the ICU message syntax
JavaScript
9
star
20

ember-power-calendar-moment

Internal utils of Ember Power Calendar built on top of Moment.js
JavaScript
9
star
21

ember-power-select-blockless

Blockless version of ember-power-select
JavaScript
8
star
22

git-repo-version

Calculates the version of a repo based on the package.json and the current SHA
JavaScript
8
star
23

ember-disable-proxy-controllers

Disables ObjectController/ArrayController for autogenerated controllers
JavaScript
7
star
24

babel-plugin-precompile-intl

Compile translations in ICU message format to invocable functions at build time
TypeScript
7
star
25

ember-power-select-places

Ember Power Select ❀️Google Places
JavaScript
6
star
26

ember-power-select-sortable

Ember-power-select <3 Ember-sortable
JavaScript
6
star
27

DahuaDoorbell2MQTT

Node.js script that connects to a Dahua Video Doorbell and broadcasts to MQTT events fired by it.
JavaScript
6
star
28

ember-power-select-collection

Ember-power-select component that {{vertical-collection}} for performance
JavaScript
5
star
29

ember-basic-dropdown-hover

Variation of ember-basic-dropdown that opens on hover
JavaScript
5
star
30

ember-k-codemod

Removes all usages of Ember.K
JavaScript
5
star
31

ember-assign-helper

Simple {{assign}} helper for Ember
JavaScript
5
star
32

ember-code-example-component

Small component to show code snippets (hbs + js + css + evaluated-result)
JavaScript
5
star
33

homeassistant-poolstation

HomeAssistant custom component for integrating the Poolstation platform.
Python
4
star
34

ember-power-calendar-luxon

Internal utils of Ember Power Calendar built on top of Luxon
JavaScript
3
star
35

marvel-api-ember-sample-app

Sample Ember.js app using marvel API
JavaScript
3
star
36

vite-plugin-svelte-inline-components

Allows you to define your components inline in tests using tagged templates
JavaScript
3
star
37

ember-simple-i18n

Simple i18n library for ember.js apps
JavaScript
3
star
38

cibernox.github.io

JavaScript
3
star
39

space-crops

JavaScript
2
star
40

home-assistant-addons

Repository with unofficial addons for home assistant
Shell
2
star
41

spanish_ccc_validator

Simple validator for spanish bank account numbers
Ruby
2
star
42

sample-app-svelte-intl-precompile

Sample app that uses svelte-intl-precompile, to use as a doc
Svelte
2
star
43

web_experiments

Web experiments using pure HTML5 and CSS3 and Javascript
JavaScript
2
star
44

sparkles-ember-basic-dropdown

Just testing sparkles-component
JavaScript
2
star
45

svelte-intl-precompile-docs

Documentation page for Svelte-intl-precompile
JavaScript
2
star
46

ember-proxy-controllers

Ember.ObjectController and Ember.ArrayController extracted as an standalone addon
JavaScript
2
star
47

ember-cli-google-libphonenumber-shim

Ember-cli addon that imports google-libphonenumber and provides shims for it
JavaScript
2
star
48

ember-i18n-errors

Extension to ember-i18n for translating error messages within the route hierarchy
JavaScript
2
star
49

sveltekit-bug-with-plugin

Repro
Svelte
1
star
50

PyPoolstation

Python library to interact the the Poolstation platform
Python
1
star
51

pinkmine

A redmine-inspired project management web app
Ruby
1
star
52

angular-football-experiment

Sample app for learn angular.
CoffeeScript
1
star
53

bencher

Simplest benchmarking library for ruby
Ruby
1
star
54

my-mu-app

Sample ember app with module unification layour
JavaScript
1
star
55

my-mu-addon

First addon ever created with the addon MU blueprint
JavaScript
1
star