From 723d920d2bc6613e86b67b9a9584928cca331f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20D=C3=A9ramond?= Date: Mon, 22 Aug 2022 13:04:46 +0200 Subject: [PATCH] =?UTF-8?q?chore(merge=20main)=20patched=20commit=20?= =?UTF-8?q?=E2=86=92=20c3c6591=20(#1469)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bundlewatch.config.json | 2 +- .stylelintrc | 3 +- js/src/scrollspy.js | 22 +- js/src/tooltip.js | 4 + js/tests/unit/scrollspy.spec.js | 44 ++ js/tests/unit/tooltip.spec.js | 19 + package-lock.json | 717 +++++++++++------- package.json | 14 +- scss/_carousel.scss | 1 + scss/_functions.scss | 2 +- scss/_list-group.scss | 3 +- scss/_root.scss | 1 + scss/_stepped-process.scss | 3 +- scss/_variables.scss | 2 +- scss/forms/_input-group.scss | 7 +- scss/mixins/_forms.scss | 1 + site/assets/scss/_navbar.scss | 2 +- site/content/docs/5.2/components/popovers.md | 8 + site/content/docs/5.2/components/scrollspy.md | 1 + .../docs/5.2/examples/features/features.css | 5 + .../docs/5.2/examples/features/index.html | 59 ++ site/content/docs/5.2/forms/layout.md | 2 +- site/content/docs/5.2/layout/grid.md | 4 +- 23 files changed, 631 insertions(+), 295 deletions(-) diff --git a/.bundlewatch.config.json b/.bundlewatch.config.json index b8d30c69a3..eb2ed3b877 100644 --- a/.bundlewatch.config.json +++ b/.bundlewatch.config.json @@ -38,7 +38,7 @@ }, { "path": "./dist/js/boosted.bundle.min.js", - "maxSize": "24.5 kB" + "maxSize": "24.75 kB" }, { "path": "./dist/js/boosted.esm.js", diff --git a/.stylelintrc b/.stylelintrc index 229e9372f5..94c8ec1552 100644 --- a/.stylelintrc +++ b/.stylelintrc @@ -26,7 +26,6 @@ "ignore": "local" } ], - "scss/selector-no-union-class-name": true, - "scss/selector-no-redundant-nesting-selector": null + "scss/selector-no-union-class-name": true } } diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 102a2e1010..f4d6671013 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -40,14 +40,16 @@ const Default = { offset: null, // TODO: v6 @deprecated, keep it for backwards compatibility reasons rootMargin: '0px 0px -25%', smoothScroll: false, - target: null + target: null, + threshold: [0.1, 0.5, 1] } const DefaultType = { offset: '(number|null)', // TODO v6 @deprecated, keep it for backwards compatibility reasons rootMargin: 'string', smoothScroll: 'boolean', - target: 'element' + target: 'element', + threshold: 'array' } /** @@ -110,6 +112,13 @@ class ScrollSpy extends BaseComponent { // TODO: on v6 target should be given explicitly & remove the {target: 'ss-target'} case config.target = getElement(config.target) || document.body + // TODO: v6 Only for backwards compatibility reasons. Use rootMargin only + config.rootMargin = config.offset ? `${config.offset}px 0px -30%` : config.rootMargin + + if (typeof config.threshold === 'string') { + config.threshold = config.threshold.split(',').map(value => Number.parseFloat(value)) + } + return config } @@ -141,8 +150,8 @@ class ScrollSpy extends BaseComponent { _getNewObserver() { const options = { root: this._rootElement, - threshold: [0.1, 0.5, 1], - rootMargin: this._getRootMargin() + threshold: this._config.threshold, + rootMargin: this._config.rootMargin } return new IntersectionObserver(entries => this._observerCallback(entries), options) @@ -187,11 +196,6 @@ class ScrollSpy extends BaseComponent { } } - // TODO: v6 Only for backwards compatibility reasons. Use rootMargin only - _getRootMargin() { - return this._config.offset ? `${this._config.offset}px 0px -30%` : this._config.rootMargin - } - _initializeTargetsAndObservables() { this._targetLinks = new Map() this._observableSections = new Map() diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 54ec0367ed..2c5f03a293 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -185,6 +185,10 @@ class Tooltip extends BaseComponent { this.tip.remove() } + if (this._config.originalTitle) { + this._element.setAttribute('title', this._config.originalTitle) + } + this._disposePopper() super.dispose() } diff --git a/js/tests/unit/scrollspy.spec.js b/js/tests/unit/scrollspy.spec.js index 2bdeb5830c..c7951e6ff1 100644 --- a/js/tests/unit/scrollspy.spec.js +++ b/js/tests/unit/scrollspy.spec.js @@ -126,6 +126,50 @@ describe('ScrollSpy', () => { expect(scrollSpy._rootElement).toBeNull() }) + it('should respect threshold option', () => { + fixtureEl.innerHTML = [ + '', + '
', + ' ', + '
' + ].join('') + + const scrollSpy = new ScrollSpy('#content', { + target: '#navigation', + threshold: [1] + }) + + expect(scrollSpy._observer.thresholds).toEqual([1]) + }) + + it('should respect threshold option markup', () => { + fixtureEl.innerHTML = [ + '', + '
', + ' ', + '
' + ].join('') + + const scrollSpy = new ScrollSpy('#content', { + target: '#navigation' + }) + + // See https://stackoverflow.com/a/45592926 + const expectToBeCloseToArray = (actual, expected) => { + expect(actual.length).toBe(expected.length) + for (const x of actual) { + const i = actual.indexOf(x) + expect(x).withContext(`[${i}]`).toBeCloseTo(expected[i]) + } + } + + expectToBeCloseToArray(scrollSpy._observer.thresholds, [0, 0.2, 1]) + }) + it('should not take count to not visible sections', () => { fixtureEl.innerHTML = [ '