diff --git a/resources/js/app.js b/resources/js/app.js index a35036d..0f98d58 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -2,5 +2,28 @@ if ('serviceWorker' in navigator) { window.addEventListener('load', () => navigator.serviceWorker.register('/sw.js')); } +// Mobile browsers only open the on-screen keyboard when focus happens during a tap, but after +// wire:navigate the next page arrives later. Links marked data-keyboard="" focus a +// hidden input during the tap so the keyboard opens, then hand focus to the page's [autofocus] +// field. The placeholder sits outside because wire:navigate replaces the body. +let keyboardPlaceholder = null; + +document.addEventListener('click', (event) => { + const link = event.target.closest?.('a[wire\\:navigate][data-keyboard]'); + if (! link || ! event.isTrusted) return; + + keyboardPlaceholder?.remove(); + keyboardPlaceholder = Object.assign(document.createElement('input'), { type: 'text', inputMode: link.dataset.keyboard }); + keyboardPlaceholder.setAttribute('aria-hidden', 'true'); + keyboardPlaceholder.tabIndex = -1; + keyboardPlaceholder.style.cssText = 'position:fixed;top:0;left:0;width:1px;height:1px;opacity:0;font-size:16px;border:0;padding:0;'; + document.documentElement.append(keyboardPlaceholder); + keyboardPlaceholder.focus({ preventScroll: true }); +}, true); + // Browsers only honour `autofocus` on a full page load, not after wire:navigate swaps the page. -document.addEventListener('livewire:navigated', () => document.querySelector('[autofocus]')?.focus()); +document.addEventListener('livewire:navigated', () => { + document.querySelector('[autofocus]')?.focus(); + keyboardPlaceholder?.remove(); + keyboardPlaceholder = null; +}); diff --git a/resources/views/components/supported-banks.blade.php b/resources/views/components/supported-banks.blade.php index a05f6fd..bc95a63 100644 --- a/resources/views/components/supported-banks.blade.php +++ b/resources/views/components/supported-banks.blade.php @@ -16,6 +16,6 @@ @endif

{{ __('No Gmail, or your bank is not yet supported?') }} - {{ __('Add transactions manually') }} + {{ __('Add transactions manually') }}

diff --git a/resources/views/livewire/transactions/form.blade.php b/resources/views/livewire/transactions/form.blade.php index 0b96e2b..557d656 100644 --- a/resources/views/livewire/transactions/form.blade.php +++ b/resources/views/livewire/transactions/form.blade.php @@ -27,7 +27,7 @@ el.setSelectionRange(caret, caret); }, }" - @unless($transaction) x-init="$nextTick(() => $el.focus())" @endunless + @unless($transaction) autofocus @endunless x-bind:value="amount" x-on:input="format($el)" class="mt-1 block min-h-12 w-full rounded-xl border-slate-300 text-base font-num focus:border-emerald-500 focus:ring-emerald-500"> @error('amount')

{{ $message }}

@enderror diff --git a/resources/views/livewire/transactions/index.blade.php b/resources/views/livewire/transactions/index.blade.php index d820cd2..5ecb121 100644 --- a/resources/views/livewire/transactions/index.blade.php +++ b/resources/views/livewire/transactions/index.blade.php @@ -22,7 +22,7 @@

{{ __('Transactions') }}

@@ -110,7 +110,7 @@ class="inline-flex min-h-11 max-w-full items-center gap-2 rounded-full bg-white @if(! $account)
{{ __('Connect Gmail') }} - {{ __('Add transactions manually') }} + {{ __('Add transactions manually') }}
@if(\App\Support\Demo::user())