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

ember-content-editable

Package Overview
Dependencies
Maintainers
1
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.

  • 0.10.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

npm version build status

ember-content-editable

Ember cli content-editable component, with placeholder and value binding. Use it just like an input or textarea, but it will autoresize for you. It also works in almost all browsers.

Installation

ember install ember-content-editable

Usage

Use it just like input or textarea.

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

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

### Options

Option NameDescriptionDefault
valueThe value to be edited""
placeholderPlaceholder displayed when value is blank""
stringInterpolatorFunction which processes / intercepts any updated value. Takes a string and returns the string to be used instead.none
classString with any extra css classnone
typenumber, text, or html. text strips out any html tags, html doesn't.html
spellcheckUses browsers spellcheck, same as with <input>none
readonlyIf true, element can't be edited but is focusablefalse
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
isText Deprecation

isText has been deprecated. You should replace isText=true with type="text", and isText=false with type="html".

editable Deprecation

editable has been deprecated in favour of disabled to be more consistent with standard input tags.

Events

You can provide actions to handle the following list of events. Arguments passed to your action are consistent with Ember implementations in places like the {{input}} helper. value is the current value of the content-editable field, component is the component instance itself, and event is the corresponding raw event object.

Event NameArguments
key-upvalue, event
key-downvalue, event
key-presscomponent, event
escape-presscomponent, event
entercomponent, event
insert-newlinecomponent, event
focus-incomponent, event
focus-outcomponent, event
mouse-entercomponent, event
mouse-leavecomponent, event

For example:

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

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

### Filtering Input If you want to filter the input, you can achieve this using the key-press event.

The following example filters the input to only allow numerical values.

{{content-editable value=age key-press=filter}}
  filter(currentValue, event) {
    const keyCode = event.which;
    if (keyCode <= 48 || keyCode >= 58) {
      event.preventDefault();
    }
  },

### Extra Tags Some browsers have a bug where extra tags including <div>s get inserted into contenteditable fields, usually when newlines are entered.

  1. If you don't care about any tags, use type="text" to strip all of them.
  2. If you do care about tags, either use display: inline-block on the content-editable component (simplest solution) or pass a function as stringInterpolator=myInterpolator to remove extra text.
myInterpolator(inputString) {
  /* Remove extra tags */
  return stringWithNoDivs;
}

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.

## License

The MIT License (MIT)

Copyright (c) 2015

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 07 Oct 2016

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