Skip to content

Commit

Permalink
fix selectors on snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSot committed Jul 5, 2022
1 parent 06054ad commit 62cf734
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions site/content/docs/5.2/components/scrollspy.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@ Scrollspy toggles the `.active` class on anchor (`<a>`) elements when the elemen

Target elements that aren't visible will be ignored and their corresponding nav items will never receive an `.active` class.

In case your scrollspy instance is initialized in a not visible wrapper, it will ignore all target elements.
In case your scrollspy instance is initialized in a non-visible wrapper, it will ignore all target elements.
As of above, when the wrapper becomes visible (its elements too), you must force scrollspy instance to check again for observable elements, using the `refresh` method.

<details>
<summary class="text-muted">Show tab example</summary>

```js

document.querySelectorAll('#nav-tab>.nav-link').forEach(el =>
el.addEventListener('shown.bs.tab', event => {
document.querySelectorAll('#nav-tab>[data-bs-toggle="tab"]').forEach(el =>{
el.addEventListener('shown.bs.tab', () => {
const target = el.getAttribute('data-bs-target')
const scrollElem = `${target}>[data-bs-spy="scroll"]`
bootstrap.ScrollSpy.getInstance(scrollElem).refresh()
const scrollElem = document.querySelector(`${target} [data-bs-spy="scroll"]`)
bootstrap.ScrollSpy.getOrCreateInstance(scrollElem).refresh()
})
)
})
```
</details>

Expand Down

0 comments on commit 62cf734

Please sign in to comment.