4.0.0 • Published 3 months ago

ember-content-editable v4.0.0

Weekly downloads
1,619
License
MIT
Repository
github
Last release
3 months ago

ember-content-editable

Greenkeeper badge Latest NPM release TravisCI Build Status Coverage 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.

Compatibility

  • Ember.js v4.4 or above
  • Ember CLI v4.4 or above
  • Node.js v14 or above

Versions

Version 3.0.0 targets ember octane apps only. If you need support for older ember versions, please see previous versions of this addon. Version 3.0.0 is based on the ember-content-editable-modifier addon.

Major changes as of 3.0.0:

  • Breaking: it is no longer possible to use two way binding within components, so consuming apps need to handle updates by providing a @onChange function!
  • Breaking: event handler names are changed to follow a consistent pattern
  • internal rewrite

Demo

Our demo page can be found here

Installation

ember install ember-content-editable

Usage

Use it just like input or textarea:

<ContentEditable @value={{this.value}} @onChange={{fn (mut this.value)}} @placeholder="Your name"/>

Options

Option NameDescriptionDefault
valueThe value to be edited""
placeholderPlaceholder displayed when value is blank""
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
onLengthExceededif maxlength is set, every action that exceeds the limit triggers this eventtotal numbers of character entered (number)
onEntertriggers when the enter key is pressedevent
onEscapetriggers when the escape key is pressedevent
onKeykeydown event propagationevent
onPastetriggers 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 in the past. 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.

4.0.0

3 months ago

4.0.0-rc.3

9 months ago

4.0.0-rc.5

9 months ago

4.0.0-rc.4

9 months ago

4.0.0-rc.6

9 months ago

4.0.0-rc.1

10 months ago

4.0.0-rc.2

9 months ago

3.0.4

1 year ago

3.0.3

1 year ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.0

2 years ago

2.0.0-rc.0

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

1.0.0-alpha.5

6 years ago

1.0.0-alpha.4

6 years ago

1.0.0-alpha.3

6 years ago

1.0.0-alpha.2

6 years ago

1.0.0-alpha.1

6 years ago

0.11.1

6 years ago

0.11.0

6 years ago

0.10.0

8 years ago

0.9.0

8 years ago

0.8.0

8 years ago

0.7.0

8 years ago

0.6.3

9 years ago

0.6.2

9 years ago

0.6.1

9 years ago

0.6.0

9 years ago

0.5.0

9 years ago

0.4.0

9 years ago

0.3.10

9 years ago

0.3.9

9 years ago

0.3.8

9 years ago

0.3.7

9 years ago

0.3.6

9 years ago

0.3.5

9 years ago

0.3.4

9 years ago

0.3.3

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago