From 44f90c7b0b23e9e42b8fc66e8c814ff56447bd69 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 13 Oct 2021 12:52:57 +0200 Subject: [PATCH] Fix focustarget in some cases Signed-off-by: Thomas Citharel --- js/src/App.vue | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/js/src/App.vue b/js/src/App.vue index bcda04912..237ab57d9 100644 --- a/js/src/App.vue +++ b/js/src/App.vue @@ -216,16 +216,18 @@ export default class App extends Vue { // Set the focus to the router view // https://marcus.io/blog/accessible-routing-vuejs setTimeout(() => { - const focusTarget = this.routerView.$el as HTMLElement; - // Make focustarget programmatically focussable - focusTarget.setAttribute("tabindex", "-1"); + const focusTarget = this.routerView?.$el as HTMLElement; + if (focusTarget) { + // Make focustarget programmatically focussable + focusTarget.setAttribute("tabindex", "-1"); - // Focus element - focusTarget.focus(); + // Focus element + focusTarget.focus(); - // Remove tabindex from focustarget. - // Reason: https://axesslab.com/skip-links/#update-3-a-comment-from-gov-uk - focusTarget.removeAttribute("tabindex"); + // Remove tabindex from focustarget. + // Reason: https://axesslab.com/skip-links/#update-3-a-comment-from-gov-uk + focusTarget.removeAttribute("tabindex"); + } }, 0); }