Focus new file name input when modal opens

pull/3094/head
bitpshr 7 years ago
parent 1950944f62
commit 63882b51d8
  1. 2
      src/app/panels/file-panel.js
  2. 9
      src/app/ui/modal-dialog-custom.js
  3. 11
      src/app/ui/modaldialog.js

@ -242,7 +242,7 @@ function filepanel (appAPI, filesProvider) {
appAPI.switchFile(filesProvider['browser'].type + '/' + newName) appAPI.switchFile(filesProvider['browser'].type + '/' + newName)
} }
}) })
}) }, null, true)
} }
/** /**

@ -6,8 +6,8 @@ module.exports = {
alert: function (text) { alert: function (text) {
modal('', yo`<div>${text}</div>`, null, { label: null }) modal('', yo`<div>${text}</div>`, null, { label: null })
}, },
prompt: function (title, text, inputValue, ok, cancel) { prompt: function (title, text, inputValue, ok, cancel, focus) {
prompt(title, text, false, inputValue, ok, cancel) prompt(title, text, false, inputValue, ok, cancel, focus)
}, },
promptPassphrase: function (title, text, inputValue, ok, cancel) { promptPassphrase: function (title, text, inputValue, ok, cancel) {
prompt(title, text, true, inputValue, ok, cancel) prompt(title, text, true, inputValue, ok, cancel)
@ -63,7 +63,7 @@ module.exports = {
} }
} }
function prompt (title, text, hidden, inputValue, ok, cancel) { function prompt (title, text, hidden, inputValue, ok, cancel, focus) {
if (!inputValue) inputValue = '' if (!inputValue) inputValue = ''
var type = hidden ? 'password' : 'text' var type = hidden ? 'password' : 'text'
var input = yo`<input type=${type} name='prompt_text' id='prompt_text' class="${css['prompt_text']}" value='${inputValue}' >` var input = yo`<input type=${type} name='prompt_text' id='prompt_text' class="${css['prompt_text']}" value='${inputValue}' >`
@ -73,6 +73,7 @@ function prompt (title, text, hidden, inputValue, ok, cancel) {
}, },
{ {
fn: () => { if (typeof cancel === 'function') cancel() } fn: () => { if (typeof cancel === 'function') cancel() }
} },
focus ? '#prompt_text' : undefined
) )
} }

@ -1,7 +1,7 @@
var yo = require('yo-yo') var yo = require('yo-yo')
var css = require('./styles/modaldialog-styles') var css = require('./styles/modaldialog-styles')
module.exports = (title, content, ok, cancel) => { module.exports = (title, content, ok, cancel, focusSelector) => {
var container = document.querySelector(`.${css.modal}`) var container = document.querySelector(`.${css.modal}`)
if (!container) { if (!container) {
document.querySelector('body').appendChild(html()) document.querySelector('body').appendChild(html())
@ -54,6 +54,15 @@ module.exports = (title, content, ok, cancel) => {
function show () { function show () {
container.style.display = 'block' container.style.display = 'block'
if (focusSelector) {
const focusTarget = document.querySelector(`.${css.modal} ${focusSelector}`)
if (focusTarget) {
focusTarget.focus()
if (typeof focusTarget.setSelectionRange === 'function') {
focusTarget.setSelectionRange(0, focusTarget.value.length)
}
}
}
} }
function removeEventListener () { function removeEventListener () {

Loading…
Cancel
Save