ember-keyboard icon indicating copy to clipboard operation
ember-keyboard copied to clipboard

Deprecation error with simple keyboard shortcut implementation

Open Wolfr opened this issue 4 years ago • 12 comments

I implemtented two simple keyboard shortcuts in my app:

{{on-key 'ctrl+m' this.toggleVisibility}}
{{on-key 'ctrl+b' this.toggleVisibility}}

These toggle the visibility of something:

import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';

export default class styleguideComponent extends Component {
  @tracked visibility = true;
  @service router;

  @action
  toggleVisibility() {
    this.visibility = !this.visibility
  }
}

However, I get a long depreciation stack trace . I think I used the latest syntax as documented here.

If I remove the 2nd shortcut, I don't get the stack trace. However, it is recommended in the docs to do it this way for multiple shortcuts.

Would anyone have an idea why I am getting this stack trace? I loved the simplicity of this package btw.

Wolfr avatar Jun 16 '20 09:06 Wolfr

Hi @Wolfr, I'm glad you're enjoying the addon! The deprecation warning you're getting is documented on the deprecations page: http://adopted-ember-addons.github.io/ember-keyboard/deprecations (see the initializer section at the bottom). I've pasted the relevant portion here:

--

ember-keyboard-first-responder-inputs initializer

ember-keyboard includes an initializer that reopens ember's TextArea and TextField components and mixes in EKMixin and EKFirstResponderOnFocusMixin. The on-key modifier added in 6.0 accomplishes a similar goal in a less intrusive and less hidden way. This initializer will be removed in 7.0. To opt out of it now and remove the deprecation warning, disable the initializer by setting emberKeyboard.disableInputsInitializer in the config/environment.js to true.

Related to this, if you were importing { initializer } from 'ember-keyboard' in any integration tests, this should no longer be necessary as Ember integration tests now run initializers themselves. This export will be removed in 7.0 as well.

--

I know it's annoying to have to deal with this as a new user, and I apologize for that. It is the best way I could come up with to ensure that we bring all users along the upgrade path safely.

lukemelia avatar Jun 16 '20 13:06 lukemelia

Excuse my ignorance, but if I put this in environment.js it complains about emberKeyboard not being found, would I then import emberKeyboard somehow? I don't understand the relation between an Ember addon and the initialisation I think.

If I try import emberKeyboard from 'ember-keyboard' I get Cannot use import statement outside a module.

I tried to add the code on L28 similar to this Gist.

Wolfr avatar Jun 16 '20 13:06 Wolfr

@Wolfr The change should look like this: https://github.com/rust-lang/crates.io/pull/2563/files#diff-695693c5dabaffb064bde5b060195ff7

lukemelia avatar Jun 16 '20 13:06 lukemelia

question: I'm using keyResponder and still getting this deprecation. Should I not be using keyResponder either? Thanks!

optikalefx avatar Oct 30 '20 16:10 optikalefx

@optikalefx no deprecation should not be triggered by using keyResponder. Did you configure your config/environment.js file (like this)?

lukemelia avatar Oct 30 '20 16:10 lukemelia

@lukemelia that was it! missed that detail. Thanks for the fast response.

optikalefx avatar Oct 30 '20 16:10 optikalefx

Hi – I wanted to check I have missed something because am still getting a couple of deprecations after adding this to my config ENV...

emberKeyboard: {
  disableInputsInitializer: true,
}

I'm using v3.27.0 of Ember and v6.0.3 of Ember Keyboard.

It removed a bunch of deprecations, but I still get these two...

Screenshot 2021-07-12 at 17 14 26

Am I missing something?

So far the only use is a very simple one in a template

<button {{on "click" this.nextQuestion}} {{on-key "Enter"}} type='button' class="w-full btn-md btn-red">Next</button>

Thanks!

chrism avatar Jul 12 '21 15:07 chrism

@chrism would you mind sharing reproduction of the issue you have? this shouldn't be a problem anymore

SergeAstapov avatar Nov 26 '21 02:11 SergeAstapov

@SergeAstapov I see the a lot of deprecation warnings too, using a simple implementation like this: <a ... {{on-key "Space" this.onKeySpace}}>

(ember-cli: 4.1.1 / ember-keyboard: 8.0.0)

screenshot_1274 screenshot_1273

didoo avatar Apr 06 '22 09:04 didoo

I see the a lot of deprecation warnings too, using a simple implementation like this: <a ... {{on-key "Space" this.onKeySpace}}>

@didoo those deprecations have been recently introduced by ember-modifier in v3.2.0. I plan to address them this or next week.

SergeAstapov avatar Apr 06 '22 21:04 SergeAstapov

Actually ember-modifier deprecations seem to be easy to fix, created #617

SergeAstapov avatar Apr 06 '22 22:04 SergeAstapov

@didoo 8.1.0 is out fixing ember-modifier deprecations

SergeAstapov avatar Apr 07 '22 03:04 SergeAstapov