-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Ajouter l'auto-scroll au
Stepper
(PIX-13201)
- Loading branch information
Showing
12 changed files
with
242 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { modifier } from 'ember-modifier'; | ||
|
||
export default modifier(function didInsert(htmlElement, [action]) { | ||
action(htmlElement); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { action } from '@ember/object'; | ||
import Service from '@ember/service'; | ||
|
||
export default class ModulixAutoScroll extends Service { | ||
#SCROLL_OFFSET_PX = 70; | ||
|
||
@action | ||
setHTMLElementScrollOffsetCssProperty(htmlElement) { | ||
htmlElement.style.setProperty('--scroll-offset', `${this.#SCROLL_OFFSET_PX}px`); | ||
} | ||
|
||
focusAndScroll( | ||
htmlElement, | ||
{ scroll, userPrefersReducedMotion, getWindowScrollY } = { | ||
scroll: this.#scroll, | ||
userPrefersReducedMotion: this.#userPrefersReducedMotion, | ||
getWindowScrollY: this.#getWindowScrollY, | ||
}, | ||
) { | ||
htmlElement.focus({ preventScroll: true }); | ||
|
||
const elementY = htmlElement.getBoundingClientRect().top + getWindowScrollY(); | ||
scroll({ | ||
top: elementY - this.#SCROLL_OFFSET_PX, | ||
behavior: userPrefersReducedMotion() ? 'instant' : 'smooth', | ||
}); | ||
} | ||
|
||
#scroll(args) { | ||
window.scroll(args); | ||
} | ||
|
||
#userPrefersReducedMotion() { | ||
const userPrefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)'); | ||
return userPrefersReducedMotion.matches; | ||
} | ||
|
||
#getWindowScrollY() { | ||
return window.scrollY; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
mon-pix/tests/integration/modifiers/modifier-did-insert_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { render } from '@1024pix/ember-testing-library'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { module, test } from 'qunit'; | ||
import sinon from 'sinon'; | ||
|
||
module('Integration | Modifier | did-insert', function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test('should call the given action', async function (assert) { | ||
// given | ||
const actionStub = sinon.stub(); | ||
this.set('action', actionStub); | ||
|
||
// when | ||
await render(hbs`<div {{modifier-did-insert this.action}}></div>`); | ||
|
||
// then | ||
sinon.assert.called(actionStub); | ||
assert.ok(true); | ||
}); | ||
}); |
Oops, something went wrong.