Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
πŸ› Koenig - Fix Firefox adding "ArrowUp" or similar to caption fields
Browse files Browse the repository at this point in the history
refs TryGhost/Ghost#9623
- Firefox unlike other browsers triggers `keypress` events for non-printable characters
- use mobiledoc-kit's `Key` class to guard against adding non-printable key values to captions
  • Loading branch information
kevinansfield committed Jun 21, 2018
1 parent fe840a2 commit 620c8fc
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/koenig-editor/addon/components/koenig-caption-input.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Component from '@ember/component';
import Key from 'mobiledoc-kit/utils/key';
import layout from '../templates/components/koenig-caption-input';
import {computed} from '@ember/object';
import {kgStyle} from 'ember-cli-ghost-spirit/helpers/kg-style';
Expand Down Expand Up @@ -64,8 +65,9 @@ export default Component.extend({
// that it's possible to start typing without explicitly focusing the input
_handleKeypress(event) {
let captionInput = this.element.querySelector('[name="caption"]');
let key = new Key(event);

if (captionInput && captionInput !== document.activeElement) {
if (captionInput && captionInput !== document.activeElement && key.isPrintableKey()) {
captionInput.value = `${captionInput.value}${event.key}`;
captionInput.focus();
event.preventDefault();
Expand Down

0 comments on commit 620c8fc

Please sign in to comment.