From 637a53cbc6902a0d23a96b768614b1de0b8a1c8a Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 5 Jan 2023 12:43:19 +0100 Subject: [PATCH] Add microinteractions to edit experiment name field [SCI-7681] --- app/assets/javascripts/shared/inline_editing.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/shared/inline_editing.js b/app/assets/javascripts/shared/inline_editing.js index de291cce5..4c4a71f84 100644 --- a/app/assets/javascripts/shared/inline_editing.js +++ b/app/assets/javascripts/shared/inline_editing.js @@ -133,20 +133,28 @@ var inlineEditing = (function() { $(document) .off('click', editBlocks) + .off('keyup', `${editBlocks}`) .off('click', `${editBlocks} .save-button`) .off('click', `${editBlocks} .cancel-button`) .off('blur', `${editBlocks} textarea, ${editBlocks} input`) + .on('keyup', `${editBlocks}`, function(e) { + if (e.keyCode === 27) { + $(`${editBlocks} .cancel-button`).click(); + } // Esc + + }) .on('click', editBlocks, function(e) { // 'A' mean that, if we click on element we will not go in edit mode var container = $(this); if (e.target.tagName === 'A') return true; if (inputField(container).attr('disabled')) { saveAllEditFields(); - - inputField(container) - .attr('disabled', false) + let input = inputField(container); + input.attr('disabled', false) .removeClass('hidden') .focus(); + input[0].selectionStart = input[0].value.length; + input[0].selectionEnd = input[0].value.length; container .attr('data-edit-mode', '1'); container.find('.view-mode')