From 22ac7e855de24b13280e9904930e58af58dbd6a7 Mon Sep 17 00:00:00 2001 From: Luffy Date: Thu, 21 Aug 2025 16:12:56 +0800 Subject: [PATCH] fix: enhance focus handling (#2595) --- docs/_coverpage.md | 2 +- src/core/event/index.js | 11 +++++++++-- test/integration/__snapshots__/docs.test.js.snap | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/_coverpage.md b/docs/_coverpage.md index e9292beaf7..654bda622d 100644 --- a/docs/_coverpage.md +++ b/docs/_coverpage.md @@ -2,7 +2,7 @@ ![logo](_media/icon.svg) -# docsify 5.0.0-rc.1 +# docsify 5.0.0-rc.1 :id=docsify > A magical documentation site generator diff --git a/src/core/event/index.js b/src/core/event/index.js index f1a55715a1..e14ecf365d 100644 --- a/src/core/event/index.js +++ b/src/core/event/index.js @@ -416,9 +416,16 @@ export function Events(Base) { // Move focus to content area if (focusEl) { - focusEl.focus(settings); + if (!focusEl.hasAttribute('tabindex')) { + focusEl.setAttribute('tabindex', '-1'); + focusEl.setAttribute('data-added-tabindex', 'true'); + } - focusEl.scrollIntoView({ behavior: 'smooth', block: 'start' }); + if (focusEl.hasAttribute('data-added-tabindex')) { + focusEl.scrollIntoView({ behavior: 'smooth' }); + } + + focusEl.focus(settings); } return focusEl; diff --git a/test/integration/__snapshots__/docs.test.js.snap b/test/integration/__snapshots__/docs.test.js.snap index ce0dc1978c..26f170ded4 100644 --- a/test/integration/__snapshots__/docs.test.js.snap +++ b/test/integration/__snapshots__/docs.test.js.snap @@ -5,7 +5,7 @@ exports[`Docs Site coverpage renders and is unchanged 1`] = `
-

logo

docsify 5.0.0-rc.1

+

logo

docsify 5.0.0-rc.1

A magical documentation site generator

  • Simple and lightweight
  • No statically built HTML files
  • Multiple themes

Get Started GitHub