notiflix / Notiflix

Notiflix is a pure JavaScript library for client-side non-blocking notifications, popup boxes, loading indicators, and more that makes your web projects much better.

Home Page:https://notiflix.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FEAT] - add option to enable/disable key prompts | Confirm dialogbox

prashil40 opened this issue · comments

Is your feature request related to a problem? Please describe.

Yes, whenever I try to use Notiflix.Confirm.Show for delete confirmation, I have to select OK / Cancel button with mouse

Describe the solution you'd like

There can be an option to enable/disable keys like "Enter" (for Ok) and "Esc" (for Cancel)

Hi @prashil40,

Notiflix is not focusing listen to the keyboard events. So, you can please create your custom solution.

An example/simple solution can be as below.

// Listener
var documentKeyupEventListener = function (event) {
  // Enter
  if (event.keyCode === 13) {
    window.document.getElementById('NXConfirmButtonOk').click();
  }

  // ESC
  if (event.keyCode === 27) {
    window.document.getElementById('NXConfirmButtonCancel').click();
  }
};

// Adding Listener
window.document.addEventListener('keyup', documentKeyupEventListener);

// Notiflix
Notiflix.Confirm.show(
  'Notiflix Confirm',
  'Do you agree with me?',
  'Yes',
  'No',
  function okCb() {
    // Removing Listener
    window.document.removeEventListener('keyup', documentKeyupEventListener);
  },
  function cancelCb() {
    // Removing Listener
    window.document.removeEventListener('keyup', documentKeyupEventListener);
  },
);

Thanks,
Furkan