Skip to content

Commit

Permalink
switch to a deactivate method
Browse files Browse the repository at this point in the history
  • Loading branch information
hannajones committed Dec 14, 2023
1 parent 6c2174f commit fb76ca0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 6 additions & 4 deletions kitsune/sumo/static/sumo/js/form-wizard-sign-in-step.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class SignInStep extends BaseFormStep {
this.#formEl.addEventListener("submit", this);
this.#emailEl.addEventListener("blur", this);
this.#emailEl.addEventListener("input", this);
this.activate();
this.#emailEl.focus();
}

disconnectedCallback() {
Expand All @@ -79,9 +79,11 @@ export class SignInStep extends BaseFormStep {
this.#emailEl.removeEventListener("input", this);
}

activate() {
this.#emailErrorEl.classList.remove("visible");
this.#emailEl.focus();
deactivate() {
if (this.shadowRoot.activeElement == this.#emailEl) {
this.#emailEl.blur();
this.#emailErrorEl.classList.remove("visible");
}
}

handleEvent(event) {
Expand Down
10 changes: 9 additions & 1 deletion kitsune/sumo/static/sumo/js/form-wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ export class FormWizard extends HTMLElement {
let name = step.getAttribute("name");
if (name === activeStep) {
step.slot = "active";
step.activate && step.activate();
} else {
step.slot = "";
step.deactivate && step.deactivate();
}
}
}
Expand Down Expand Up @@ -425,6 +425,14 @@ export class BaseFormStep extends HTMLElement {
this.render(prevState, this.#state);
}

/**
* Method that can be implemented to handle any clean up needed when a form
* step is no longer active e.g. clearing error states.
*/
deactivate() {
// NOOP
}

/**
* Method that gets run whenever the element's state changes. Can be used to
* specify how the DOM should update in response to state changes. `prevState`
Expand Down

0 comments on commit fb76ca0

Please sign in to comment.