Skip to content

Commit

Permalink
Forces controller initialization on every personal details form
Browse files Browse the repository at this point in the history
  • Loading branch information
ddippolito committed Jun 5, 2024
1 parent d5d6a9e commit 43ba277
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { Controller } from '@hotwired/stimulus';

export default class extends Controller {
export default class MobileFocusController extends Controller {
connect() {
this.handleMobilePageFocus();
}

static detectMobile() {
return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}

handleMobilePageFocus() {
if (!this.detectMobile()) {
if (!this.constructor.detectMobile()) {
return;
}

if (window.location.href.includes('profile/personal-details')) {
const skipLinkElement = document.getElementsByClassName('govuk-skip-link');
const skipLinkElement = document.querySelector('.govuk-skip-link');

if (skipLinkElement && skipLinkElement.length > 0) {
skipLinkElement[0].focus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

.govuk-grid-row
.govuk-grid-column-two-thirds
= form_for @step, url: { action: :update }, method: :post, as: :personal_details_form do |f|
= form_for @step, url: { action: :update }, method: :post, as: :personal_details_form, html: { data: { controller: "mobile-focus" } } do |f|
= f.govuk_error_summary

= f.govuk_fieldset legend: { text: t(".heading"), tag: "h1", size: "l" }, caption: { text: t(".caption"), size: "l" } do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

.govuk-grid-row
.govuk-grid-column-two-thirds
= form_for @step, url: { action: :update }, method: :post, as: :personal_details_form do |f|
= form_for @step, url: { action: :update }, method: :post, as: :personal_details_form, html: { data: { controller: "mobile-focus" } } do |f|
= f.govuk_error_summary

= f.govuk_radio_buttons_fieldset :phone_number_provided, legend: { text: t(".heading"), tag: "h1", size: "l" }, caption: { text: t(".caption"), size: "l" } do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

.govuk-grid-row
.govuk-grid-column-two-thirds
= form_for @step, url: { action: :update }, method: :post, as: :personal_details_form do |f|
= form_for @step, url: { action: :update }, method: :post, as: :personal_details_form, html: { data: { controller: "mobile-focus" } } do |f|
= f.govuk_error_summary

= f.govuk_radio_buttons_fieldset :right_to_work_in_uk,
Expand Down

0 comments on commit 43ba277

Please sign in to comment.