mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor(input): improve focus handling, alpha39 fixes
This commit is contained in:
@@ -176,8 +176,12 @@ export function hasPointerMoved(threshold, startCoord, endCoord) {
|
||||
(Math.abs(startCoord.x - endCoord.x) > threshold || Math.abs(startCoord.y - endCoord.y) > threshold);
|
||||
}
|
||||
|
||||
export function isActive(ele) {
|
||||
return !!(ele && (document.activeElement === ele));
|
||||
}
|
||||
|
||||
export function hasFocus(ele) {
|
||||
return !!(ele && (document.activeElement === ele.nativeElement || document.activeElement === ele));
|
||||
return isActive(ele) && (ele.parentElement.querySelector(':focus') === ele);
|
||||
}
|
||||
|
||||
export function isTextInput(ele) {
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
import {raf, ready} from './dom'
|
||||
|
||||
/* Focus Outline
|
||||
* --------------------------------------------------
|
||||
* When a keydown event happens, from a tab key, then the
|
||||
* 'key-input' class is added to the body element so focusable
|
||||
* elements have an outline. On a mousedown or touchstart
|
||||
* event then the 'key-input' class is removed.
|
||||
*/
|
||||
|
||||
|
||||
let isKeyInputEnabled = false
|
||||
|
||||
function keyDown(ev) {
|
||||
if (!isKeyInputEnabled && ev.keyCode == 9) {
|
||||
isKeyInputEnabled = true
|
||||
raf(enableKeyInput)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function enableKeyInput() {
|
||||
document.body.classList[isKeyInputEnabled ? 'add' : 'remove']('key-input')
|
||||
|
||||
if (isKeyInputEnabled) {
|
||||
document.addEventListener('mousedown', pointerDown)
|
||||
document.addEventListener('touchstart', pointerDown)
|
||||
|
||||
} else {
|
||||
document.removeEventListener('mousedown', pointerDown)
|
||||
document.removeEventListener('touchstart', pointerDown)
|
||||
}
|
||||
}
|
||||
|
||||
function pointerDown() {
|
||||
isKeyInputEnabled = false
|
||||
raf(enableKeyInput)
|
||||
}
|
||||
|
||||
|
||||
ready().then(function() {
|
||||
document.addEventListener('keydown', keyDown)
|
||||
})
|
||||
Reference in New Issue
Block a user