diff --git a/scss/_lichess-pgn-viewer.lib.scss b/scss/_lichess-pgn-viewer.lib.scss index 6f5422b..9865afe 100644 --- a/scss/_lichess-pgn-viewer.lib.scss +++ b/scss/_lichess-pgn-viewer.lib.scss @@ -1,4 +1,5 @@ $c-site-hue: 37 !default; +$c-primary: hsl(209, 77%, 50%) !default; $c-accent: hsl(88, 62%, 37%) !default; $c-accent-over: white !default; $c-bg: hsl($c-site-hue, 5%, 18%) !default; @@ -46,4 +47,8 @@ $c-interesting: hsl(307, 80%, 70%) !default; box-shadow: none; } } + + &:focus { + outline: auto 2px $c-primary; + } } diff --git a/src/ctrl.ts b/src/ctrl.ts index 655016e..cbf2430 100644 --- a/src/ctrl.ts +++ b/src/ctrl.ts @@ -27,7 +27,7 @@ export default class Ctrl { curNode = (): AnyNode => this.game.nodeAt(this.path) || this.game.moves; curData = (): InitialOrMove => this.game.dataAt(this.path) || this.game.initial; - goTo = (to: GoTo) => { + goTo = (to: GoTo, focus = true) => { const path = to == 'first' ? Path.root @@ -36,18 +36,18 @@ export default class Ctrl { : to == 'next' ? this.game.nodeAt(this.path)?.children[0]?.data.path : this.game.pathAtMainlinePly('last'); - this.toPath(path || this.path); + this.toPath(path || this.path, focus); }; canGoTo = (to: GoTo) => (to == 'prev' || to == 'first' ? !this.path.empty() : !!this.curNode().children[0]); - toPath = (path: Path) => { + toPath = (path: Path, focus = true) => { this.path = path; this.pane = 'board'; this.autoScrollRequested = true; this.redrawGround(); this.redraw(); - this.focus(); + if (focus) this.focus(); }; focus = () => this.div?.focus(); diff --git a/src/view/main.ts b/src/view/main.ts index 3a0f75a..21fd736 100644 --- a/src/view/main.ts +++ b/src/view/main.ts @@ -42,14 +42,11 @@ const renderBoard = (ctrl: Ctrl): VNode => hook: onInsert(el => { el.addEventListener('click', ctrl.focus); if (ctrl.opts.scrollToMove && !('ontouchstart' in window)) - bindNonPassive( - 'wheel', - stepwiseScroll((e: WheelEvent, scroll: boolean) => { - e.preventDefault(); - if (e.deltaY > 0 && scroll) ctrl.goTo('next'); - else if (e.deltaY < 0 && scroll) ctrl.goTo('prev'); - }) - ); + el.addEventListener('wheel', stepwiseScroll((e: WheelEvent, scroll: boolean) => { + e.preventDefault(); + if (e.deltaY > 0 && scroll) ctrl.goTo('next', false); + else if (e.deltaY < 0 && scroll) ctrl.goTo('prev', false); + })); }), }, h('div.cg-wrap')