Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

ember-one-way-input

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-one-way-input

Native one way input

latest
Source
npmnpm
Version
0.4.0
Version published
Weekly downloads
15
400%
Maintainers
2
Weekly downloads
 
Created
Source

ember-one-way-input Build Status npm version

Credit: @rwjblue's twiddle

Demo: http://ember-twiddle.com/2d7246875098d0dbb4a4

This addon provides a simple one way input that sends an update action when it is updated, and can be used like any other input.

  {{one-way-input
      value=currentValue
      update=(action (mut currentValue))
      onenter=(action "commit")
      onescape=(action "escape")
  }}

The input can also be used as a checkbox:

  {{one-way-input
      type="checkbox"
      checked=currentValue
      update=(action (mut currentValue))
  }}

The component's KEY_EVENTS attribute can be overwritten to provide custom handlers for various keycodes on the keyUp event.

KEY_EVENTS: {
  '13': 'onenter',
  '27': 'onescape'
}

This means that the onenter and onescape actions will fire if their corresponding key codes are received in the keyUp event.

Why?

With Glimmer landing in 1.13.x, native <input> elements can now be used in your apps, without the two way binding semantics of the {{input}} helper. Shifting to one way bindings ("data down, actions up") makes your app easier to reason about and debug, and is generally the idiomatic way of building Ember apps going forward.

Unfortunately, there is a small gotcha with using a native input like so:

<input
  value={{currentValue}}
  oninput={{action (mut currentValue) value="target.value"}}
>

In the following demo, move your cursor to a character in the middle of the value, and attempt to input new text. You will notice that your cursor immediately jumps to the end of the string, which is entirely unintuitive and annoying.

This addon fixes the cursor jumping issue by using readDOMAttr, which provides a way to read an element's attribute and update the last value Ember knows about at the same time. This makes setting an attribute idempotent.

Compatibility

This addon will work on Ember versions 1.13.x and up.

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.

DockYard, Inc © 2015

@dockyard

Licensed under the MIT license

Keywords

ember-addon

FAQs

Package last updated on 07 Dec 2015

Did you know?

Socket

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