fix: improve code group explicit/implicit logic

pull/3651/head
wuxh 2 years ago
parent df8753bd92
commit 75fc8ac740
No known key found for this signature in database
GPG Key ID: 4E035332466F0370

@ -7,7 +7,7 @@ export function useCodeGroups() {
Array.from(el.children).forEach((child) => { Array.from(el.children).forEach((child) => {
child.classList.remove('active') child.classList.remove('active')
}) })
el.children[0].classList.add('active') el.querySelector('div[class^="language"]')?.classList.add('active')
}) })
}) })
} }
@ -24,19 +24,21 @@ export function useCodeGroups() {
const i = Array.from(group.querySelectorAll('input')).indexOf(el) const i = Array.from(group.querySelectorAll('input')).indexOf(el)
if (i < 0) return if (i < 0) return
const blocks = group.querySelector('.blocks') const codeBlocks = group.querySelectorAll(
if (!blocks) return '.blocks > div[class^="language"]'
)
if (!codeBlocks) return
const current = Array.from(blocks.children).find((child) => const activeBlock = Array.from(codeBlocks).find((block) =>
child.classList.contains('active') block.classList.contains('active')
) )
if (!current) return if (!activeBlock) return
const next = blocks.children[i] const nextBlock = codeBlocks[i]
if (!next || current === next) return if (!nextBlock || activeBlock === nextBlock) return
current.classList.remove('active') activeBlock.classList.remove('active')
next.classList.add('active') nextBlock.classList.add('active')
const label = group?.querySelector(`label[for="${el.id}"]`) const label = group?.querySelector(`label[for="${el.id}"]`)
label?.scrollIntoView({ block: 'nearest' }) label?.scrollIntoView({ block: 'nearest' })

Loading…
Cancel
Save