Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember-content-editable

Package Overview
Dependencies
Maintainers
2
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-content-editable

A content-editable component for ember-cli that just works.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
933
decreased by-7.16%
Maintainers
2
Weekly downloads
 
Created
Source

ember-content-editable

Greenkeeper badge Latest NPM release TravisCI Build Status Code Climate Ember Observer Score Dependencies Dev Dependencies

Ember cli contenteditable component, with placeholder and value binding. Use it just like an input or textarea, but it will autoresize for you.

Installation

ember install ember-content-editable

Versions

Since version 1.0.0 this addon has been rewritten to focus on using contenteditable elements as input replacements. In case you need previously available functionality or IE9 or IE10 support, 0.11.1 was the last release of the 0.x.x series.

Major changes as of 1.0.0:

  • removes jquery dependencies
  • removes IE9 and IE10 support
  • no observers and computed properties were harmed
  • only supports type text and therefore removes the type property completely
  • removes stringInterpolator functionality

Demo

Our demo page can be found here

Usage

Use it just like input or textarea:

{{content-editable value=name placeholder="Your name"}}

You can also pass in an extra CSS class if required, and of course specify the tag:

{{content-editable value=name
                   placeholder="Your name"
                   class="name-field"
                   tagName="h3"}}

And lastly, you can also pass value as a positional parameter:

{{content-editable name placeholder="Your name"}}

Options

Option NameDescriptionDefault
valueThe value to be edited""
placeholderPlaceholder displayed when value is blank""
classString with any extra css classnone
spellcheckUses browsers spellcheck, same as with <input>none
disabledIf true, element can't be edited, focused or tabbed tofalse
maxlengthMaximum length of the input, in charactersnone
allowNewlinesIf false, linebreaks can't be enteredtrue
autofocusIf true, the element will be focused once inserted into the documentfalse
clearPlaceholderOnFocusIf true, the placeholder will be cleared as soon as the element gains focus (even if no content is present yet)false

Events

This addon supports events supported by the ember component model (except for keyboard events). See the ember documentation for details or the dummy app within the test folder for an example. As this addon uses keyboard events slightly renamed hooks are available as making use of the default hooks would override the addons implementation.

eventdescriptionargument
insert-newlineif allowNewlines is set to true, this event is triggered whenever a new line is insertedevent
length-exceededif maxlength is set, every action that exceeds the limit triggers this eventtotal numbers of character entered (number)
entertriggers when the enter key is pressedevent
escape-presstriggers when the escape key is pressedevent
key-upkeyUp replacementevent
key-presskeyPress replacementevent
key-downkeyDown replacementevent
pastetriggers when content is pasted successfully (does not fire when maxlength is exceeded)pasted text content (string)

Customizing Placeholder Color

.ember-content-editable:empty {
  color: rgba(0,0,0,0.6);
}

Common Problems

These are some solutions to common problems browsers have with contenteditable elements.

Tab Index

The tabindex attribute is bound to the element in the DOM, but only certain tags support it.

The following elements support the tabindex attribute: A, AREA, BUTTON, INPUT, OBJECT, SELECT, and TEXTAREA.

So to use tabindex, you'll also need to set tagName to one of those.

Newlines aren't showing

Try using whitespace: pre-line; or whitespace: pre-wrap; in your CSS.

I can't blur the element

A solution to this is to call window.getSelection().removeAllRanges() after you call blur() on the element.

For example, if you have enter='endEditing' on your content-editable, the following action would prevent the newline and blur the element.

endEditing(contentEditable, event) {
  event.preventDefault();
  contentEditable.element.blur();
  window.getSelection().removeAllRanges();
}

Cursor appears too big when element is empty

Setting display: block; in CSS seems to solve this.

Acknowledements

AddJAm has done a great job writing and maintaining this addon for a long time. Thanks guys.

Contributions

If you want to report a bug, please open a new issue. Any bugs that are not totally obvious should include a way to reproduce the issue (like ember-twiddle) or a failing test. Or even better, provide a PR which tests and fixes the issue.

In case you find there is a feature missing, please provide a PR with corresponding test coverage. Please keep in mind to keep addons lightweight. If in doubt, open an issue first and see what others think about it.

Keywords

FAQs

Package last updated on 03 May 2018

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc