Skip to content

fix: input focus on delete/change password #100

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions resources/js/components/DeleteUser.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { useForm } from '@inertiajs/vue3';
import { ref } from 'vue';
import { useTemplateRef } from 'vue';

// Components
import HeadingSmall from '@/components/HeadingSmall.vue';
@@ -19,7 +19,7 @@ import {
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';

const passwordInput = ref<HTMLInputElement | null>(null);
const passwordInput = useTemplateRef('passwordInput');

const form = useForm({
password: '',
@@ -31,7 +31,7 @@ const deleteUser = (e: Event) => {
form.delete(route('profile.destroy'), {
preserveScroll: true,
onSuccess: () => closeModal(),
onError: () => passwordInput.value?.focus(),
onError: () => passwordInput.value?.$el.focus(),
onFinish: () => form.reset(),
});
};
14 changes: 7 additions & 7 deletions resources/js/pages/settings/Password.vue
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import InputError from '@/components/InputError.vue';
import AppLayout from '@/layouts/AppLayout.vue';
import SettingsLayout from '@/layouts/settings/Layout.vue';
import { Head, useForm } from '@inertiajs/vue3';
import { ref } from 'vue';
import { useTemplateRef } from 'vue';

import HeadingSmall from '@/components/HeadingSmall.vue';
import { Button } from '@/components/ui/button';
@@ -18,8 +18,8 @@ const breadcrumbItems: BreadcrumbItem[] = [
},
];

const passwordInput = ref<HTMLInputElement | null>(null);
const currentPasswordInput = ref<HTMLInputElement | null>(null);
const passwordInput = useTemplateRef('passwordInput');
const currentPasswordInput = useTemplateRef('currentPasswordInput');

const form = useForm({
current_password: '',
@@ -34,15 +34,15 @@ const updatePassword = () => {
onError: (errors: any) => {
if (errors.password) {
form.reset('password', 'password_confirmation');
if (passwordInput.value instanceof HTMLInputElement) {
passwordInput.value.focus();
if (passwordInput.value?.$el instanceof HTMLInputElement) {
passwordInput.value.$el.focus();
}
}

if (errors.current_password) {
form.reset('current_password');
if (currentPasswordInput.value instanceof HTMLInputElement) {
currentPasswordInput.value.focus();
if (currentPasswordInput.value?.$el instanceof HTMLInputElement) {
currentPasswordInput.value.$el.focus();
}
}
},