From 2eeba8ce576e5c327934b88fb5d9b94224ece5fd Mon Sep 17 00:00:00 2001 From: izayl Date: Wed, 10 May 2023 14:15:36 +0800 Subject: [PATCH 1/2] feat: code group tab scrollIntoView --- src/client/app/composables/codeGroups.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/client/app/composables/codeGroups.ts b/src/client/app/composables/codeGroups.ts index e4bd5c5c731c..e77139e1af22 100644 --- a/src/client/app/composables/codeGroups.ts +++ b/src/client/app/composables/codeGroups.ts @@ -8,6 +8,13 @@ export function useCodeGroups() { if (el.matches('.vp-code-group input')) { // input <- .tabs <- .vp-code-group const group = el.parentElement?.parentElement + + const label = group?.querySelector(`label[for="${el.id}"]`) + label?.scrollIntoView({ + behavior: 'smooth', + block: 'nearest', + inline: 'nearest' + }) const i = Array.from(group?.querySelectorAll('input') || []).indexOf(el) const current = group?.querySelector('div[class*="language-"].active') From 52a335fe741fb35e382951c74f7864bc2e4aed73 Mon Sep 17 00:00:00 2001 From: izayl Date: Thu, 11 May 2023 20:57:36 +0800 Subject: [PATCH 2/2] feat: scroll to center --- src/client/app/composables/codeGroups.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/app/composables/codeGroups.ts b/src/client/app/composables/codeGroups.ts index e77139e1af22..ee068622bfcf 100644 --- a/src/client/app/composables/codeGroups.ts +++ b/src/client/app/composables/codeGroups.ts @@ -13,7 +13,7 @@ export function useCodeGroups() { label?.scrollIntoView({ behavior: 'smooth', block: 'nearest', - inline: 'nearest' + inline: 'center' }) const i = Array.from(group?.querySelectorAll('input') || []).indexOf(el)