Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix(navigation): corrige bugs de fermeture du composant [DS-3617, DS-3619] #840

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/analytics/example/spa/agnostic/route.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

e.preventDefault();
window.history.pushState({}, '', href);
urlLocationHandler();
handleUrlLocation();
});

// create an object that maps the url to the template, title, and description
Expand Down Expand Up @@ -38,7 +38,7 @@
};

// create a function that handles the url location
const urlLocationHandler = async () => {
const handleUrlLocation = async () => {
let location = window.location.href.replace(HREF, ''); // get the url route

// get the route object from the urlRoutes object
Expand All @@ -56,9 +56,9 @@
};

// add an event listener to the window that watches for url changes
window.onpopstate = urlLocationHandler;
// call the urlLocationHandler function to handle the initial url
window.route = urlLocationHandler;
// call the urlLocationHandler function to handle the initial url
urlLocationHandler();
window.onpopstate = handleUrlLocation;
// call the handleUrlLocation function to handle the initial url
window.route = handleUrlLocation;
// call the handleUrlLocation function to handle the initial url
handleUrlLocation();
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class ComponentActionee extends Actionee {
const button = this.element.getDescendantInstances('ButtonActionee', null, true)[0];
if (button) button.isMuted = true;
this._validatedInput = node.querySelector('input');
this._inputValidationHandler = this._handleInputValidation.bind(this);
if (this._validatedInput) this._validatedInput.addEventListener('keydown', this._inputValidationHandler);
this._handlingInputValidation = this._handleInputValidation.bind(this);
if (this._validatedInput) this._validatedInput.addEventListener('keydown', this._handlingInputValidation);
}

_handleInputValidation (e) {
Expand Down Expand Up @@ -141,7 +141,7 @@ class ComponentActionee extends Actionee {

dispose () {
if (this._validatedInput) {
this._validatedInput.removeEventListener('keydown', this._inputValidationHandler);
this._validatedInput.removeEventListener('keydown', this._handlingInputValidation);
}

super.dispose();
Expand Down
7 changes: 3 additions & 4 deletions src/analytics/script/integration/core/actionee.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,8 @@ class Actionee extends api.core.Instance {
listenClick (target) {
if (target) {
this._clickTarget = target;
this._clickHandler = this.handleClick.bind(this);
this._clickTarget.addEventListener('click', this._clickHandler, { capture: true });
} else this.listen('click', this.handleClick.bind(this), { capture: true });
this._clickTarget.addEventListener('click', this.handlingClick, { capture: true });
} else this.listenClick({ capture: true });
}

handleClick () {
Expand Down Expand Up @@ -255,7 +254,7 @@ class Actionee extends api.core.Instance {

dispose () {
if (this._clickTarget) {
this._clickTarget.removeEventListener('click', this._clickHandler);
this._clickTarget.removeEventListener('click', this.handlingClick);
}
super.dispose();
}
Expand Down
11 changes: 3 additions & 8 deletions src/component/header/script/header/header-modal.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import api from '../../api.js';

class HeaderModal extends api.core.Instance {
constructor () {
super();
this._clickHandling = this.clickHandler.bind(this);
}

static get instanceClassName () {
return 'HeaderModal';
}
Expand All @@ -23,18 +18,18 @@ class HeaderModal extends api.core.Instance {
const modal = this.element.getInstance('Modal');
if (!modal) return;
modal.isEnabled = true;
this.listen('click', this._clickHandling, { capture: true });
this.listenClick({ capture: true });
}

deactivateModal () {
const modal = this.element.getInstance('Modal');
if (!modal) return;
modal.conceal();
modal.isEnabled = false;
this.unlisten('click', this._clickHandling, { capture: true });
this.unlistenClick({ capture: true });
}

clickHandler (e) {
handleClick (e) {
if (e.target.matches('a, button') && !e.target.matches('[aria-controls]') && !e.target.matches(api.core.DisclosureSelector.PREVENT_CONCEAL)) {
const modal = this.element.getInstance('Modal');
modal.conceal();
Expand Down
20 changes: 12 additions & 8 deletions src/component/navigation/script/navigation/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,33 @@ class Navigation extends api.core.CollapsesGroup {
super.init();
this.clicked = false;
this.out = false;
this.listen('focusout', this.focusOutHandler.bind(this));
this.listen('mousedown', this.mouseDownHandler.bind(this));
this.addEmission(api.core.RootEmission.CLICK, this._handleRootClick.bind(this));
this.listen('mousedown', this.handleMouseDown.bind(this));
this.listenClick({ capture: true });
}

validate (member) {
return super.validate(member) && member.element.node.matches(api.internals.legacy.isLegacy ? NavigationSelector.COLLAPSE_LEGACY : NavigationSelector.COLLAPSE);
}

mouseDownHandler (e) {
handleMouseDown (e) {
if (!this.isBreakpoint(api.core.Breakpoints.LG) || this.index === -1 || !this.current) return;
this.position = this.current.node.contains(e.target) ? NavigationMousePosition.INSIDE : NavigationMousePosition.OUTSIDE;
this.requestPosition();
}

clickHandler (e) {
if (e.target.matches('a, button') && !e.target.matches('[aria-controls]') && !e.target.matches(api.core.DisclosureSelector.PREVENT_CONCEAL)) this.index = -1;
handleClick (e) {
if (e.target.matches('a, button') && !e.target.matches('[aria-controls]') && !e.target.matches(api.core.DisclosureSelector.PREVENT_CONCEAL)) {
this.index = -1;
}
}

focusOutHandler (e) {
_handleRootClick (target) {
if (!this.isBreakpoint(api.core.Breakpoints.LG)) return;
this.out = true;
this.requestPosition();
if (!this.node.contains(target)) {
this.out = true;
this.requestPosition();
}
}

requestPosition () {
Expand Down