diff --git a/web/app/common/polyfills.js b/web/app/common/polyfills.js index 05c15b1d..aad6a808 100644 --- a/web/app/common/polyfills.js +++ b/web/app/common/polyfills.js @@ -1,4 +1,5 @@ import 'core-js/es7/promise'; +import 'focus-visible'; export default function loadPolyfills() { const fillCoreJs = () => { diff --git a/web/app/components/comment/__action/comment__action.scss b/web/app/components/comment/__action/comment__action.scss index 9e3a0fda..39452f45 100644 --- a/web/app/components/comment/__action/comment__action.scss +++ b/web/app/components/comment/__action/comment__action.scss @@ -9,10 +9,6 @@ color: #31c7c5; } - &:focus { - outline: none; - } - + .comment__action { margin-left: 8px; } diff --git a/web/app/components/comment/__control/comment__control.scss b/web/app/components/comment/__control/comment__control.scss index dfc8b44c..53caeef3 100644 --- a/web/app/components/comment/__control/comment__control.scss +++ b/web/app/components/comment/__control/comment__control.scss @@ -10,8 +10,4 @@ &:hover { color: #0aa; } - - &:focus { - outline: none; - } } diff --git a/web/app/components/comment/__controls/comment__controls.scss b/web/app/components/comment/__controls/comment__controls.scss index 90b58b37..056a60ad 100644 --- a/web/app/components/comment/__controls/comment__controls.scss +++ b/web/app/components/comment/__controls/comment__controls.scss @@ -4,9 +4,10 @@ user-select: none; font-size: 14px; font-weight: 700; + opacity: 0; - @media (hover: hover) { - font-weight: 700; - opacity: 0; + &:hover, + &:focus-within { + opacity: 1; } } diff --git a/web/app/components/comment/__vote/comment__vote.scss b/web/app/components/comment/__vote/comment__vote.scss index dd3c9100..cf6dc84c 100644 --- a/web/app/components/comment/__vote/comment__vote.scss +++ b/web/app/components/comment/__vote/comment__vote.scss @@ -8,7 +8,6 @@ background: url('comment__vote.svg') center no-repeat; background-size: contain; cursor: pointer; - outline: none; &:hover { background-image: url('_selected/comment__vote_selected.svg'); diff --git a/web/app/components/input/__button/input__button.scss b/web/app/components/input/__button/input__button.scss index e8c4806c..92c6948b 100644 --- a/web/app/components/input/__button/input__button.scss +++ b/web/app/components/input/__button/input__button.scss @@ -7,10 +7,6 @@ border-radius: 2px; cursor: pointer; - &:focus { - outline: none; - } - &:disabled { opacity: 0.5; pointer-events: none; diff --git a/web/app/components/root/__show-more/root__show-more.scss b/web/app/components/root/__show-more/root__show-more.scss index c3186bf4..1b0fe800 100644 --- a/web/app/components/root/__show-more/root__show-more.scss +++ b/web/app/components/root/__show-more/root__show-more.scss @@ -18,8 +18,4 @@ &:focus { background: #0aa; } - - &:focus { - outline: none; - } } diff --git a/web/app/embed.js b/web/app/embed.js index efc07637..b801dcc0 100644 --- a/web/app/embed.js +++ b/web/app/embed.js @@ -60,6 +60,7 @@ function init() { node: null, back: null, closeEl: null, + iframe: null, style: null, init(user) { this.animationStop(); @@ -97,8 +98,6 @@ function init() { #${remarkRootId}-close { top: 0px; right: 400px; - width: 30px; - height: 30px; position: absolute; text-align: center; font-size: 25px; @@ -107,6 +106,7 @@ function init() { border-color: transparent; border-width: 0; padding: 0; + margin-right: 4px; background-color: transparent; } @media all and (max-width: 430px) { @@ -150,14 +150,19 @@ function init() { verticalscrolling="no" horizontalscrolling="no" />`; + this.iframe = this.node.querySelector('iframe'); + this.iframe.onload = () => { + this.iframe.contentDocument.addEventListener('keydown', this.onKeyDown); + }; this.node.appendChild(this.closeEl); document.body.appendChild(this.style); document.body.appendChild(this.back); document.body.appendChild(this.node); + document.addEventListener('keydown', this.onKeyDown); setTimeout(() => { this.back.setAttribute('data-animation', ''); this.node.setAttribute('data-animation', ''); - this.closeEl.focus(); + this.iframe.focus(); }, 400); }, close() { @@ -168,6 +173,7 @@ function init() { if (this.back) { this.back.removeAttribute('data-animation'); } + document.removeEventListener('keydown', this.onKeyDown); }, delay: null, events: ['', 'webkit', 'moz', 'MS', 'o'].map(prefix => (prefix ? `${prefix}TransitionEnd` : 'transitionend')), @@ -179,6 +185,12 @@ function init() { this.delay = setTimeout(this.animationStop, 1000); this.events.forEach(event => el.addEventListener(event, this.animationStop, false)); }, + onKeyDown(e) { + // ESCAPE key pressed + if (e.keyCode == 27) { + userInfo.close(); + } + }, animationStop() { const t = userInfo; if (!t.node) { diff --git a/web/iframe.html b/web/iframe.html index d65d6c24..e9dc515c 100644 --- a/web/iframe.html +++ b/web/iframe.html @@ -64,6 +64,10 @@ transform: scale(0); } } + + :focus:not(.focus-visible):not(.button) { + outline: none; + } diff --git a/web/package-lock.json b/web/package-lock.json index 285a58c3..cb6f9fa1 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -4800,6 +4800,11 @@ } } }, + "focus-visible": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/focus-visible/-/focus-visible-4.1.5.tgz", + "integrity": "sha512-yo/njtk/BB4Z2euzaZe3CZrg4u5s5uEi7ZwbHBJS2quHx51N0mmcx9nTIiImUGlgy+vf26d0CcQluahBBBL/Fw==" + }, "follow-redirects": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.4.1.tgz", diff --git a/web/package.json b/web/package.json index a49abbea..f04f5c52 100644 --- a/web/package.json +++ b/web/package.json @@ -62,6 +62,7 @@ "axios": "^0.18.0", "bem-react-helper": "^1.1.2", "core-js": "^2.5.7", + "focus-visible": "^4.1.5", "preact": "^8.2.9", "preact-redux": "^2.0.3", "redux": "^4.0.0"