Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 1 | <template> |
Yoshie Muranaka | 74f8687 | 2020-02-10 12:28:37 -0800 | [diff] [blame] | 2 | <div class="app-container"> |
| 3 | <app-header ref="focusTarget" class="app-header" @refresh="refresh" /> |
| 4 | <app-navigation class="app-navigation" /> |
| 5 | <page-container class="app-content"> |
| 6 | <router-view ref="routerView" :key="routerKey" /> |
Dixsie Wolmers | 970ea7d | 2020-11-16 16:46:01 -0600 | [diff] [blame] | 7 | <!-- Scroll to top button --> |
| 8 | <button-back-to-top /> |
Yoshie Muranaka | 74f8687 | 2020-02-10 12:28:37 -0800 | [diff] [blame] | 9 | </page-container> |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 10 | </div> |
| 11 | </template> |
| 12 | |
| 13 | <script> |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 14 | import AppHeader from '@/components/AppHeader'; |
| 15 | import AppNavigation from '@/components/AppNavigation'; |
SurenNeware | 6185909 | 2020-10-01 09:37:32 +0530 | [diff] [blame] | 16 | import PageContainer from '@/components/Global/PageContainer'; |
Dixsie Wolmers | 970ea7d | 2020-11-16 16:46:01 -0600 | [diff] [blame] | 17 | import ButtonBackToTop from '@/components/Global/ButtonBackToTop'; |
| 18 | |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 19 | export default { |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 20 | name: 'App', |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 21 | components: { |
| 22 | AppHeader, |
Yoshie Muranaka | 8d12910 | 2019-12-19 09:51:55 -0800 | [diff] [blame] | 23 | AppNavigation, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 24 | PageContainer, |
Dixsie Wolmers | 970ea7d | 2020-11-16 16:46:01 -0600 | [diff] [blame] | 25 | ButtonBackToTop, |
Derick Montague | 75b4832 | 2019-12-06 01:24:41 -0600 | [diff] [blame] | 26 | }, |
Yoshie Muranaka | eb154bb | 2020-02-07 12:18:45 -0800 | [diff] [blame] | 27 | data() { |
| 28 | return { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 29 | routerKey: 0, |
Yoshie Muranaka | eb154bb | 2020-02-07 12:18:45 -0800 | [diff] [blame] | 30 | }; |
| 31 | }, |
Derick Montague | 75b4832 | 2019-12-06 01:24:41 -0600 | [diff] [blame] | 32 | watch: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 33 | $route: function () { |
Derick Montague | 75b4832 | 2019-12-06 01:24:41 -0600 | [diff] [blame] | 34 | // $nextTick = DOM updated |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 35 | this.$nextTick(function () { |
Derick Montague | 75b4832 | 2019-12-06 01:24:41 -0600 | [diff] [blame] | 36 | // Get the focusTarget DOM element |
| 37 | let focusTarget = this.$refs.focusTarget.$el; |
| 38 | |
| 39 | // Make focustarget programmatically focussable |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 40 | focusTarget.setAttribute('tabindex', '-1'); |
Derick Montague | 75b4832 | 2019-12-06 01:24:41 -0600 | [diff] [blame] | 41 | |
| 42 | // Focus element |
| 43 | focusTarget.focus(); |
| 44 | |
| 45 | // Remove tabindex from focustarget |
| 46 | // Reason: https://axesslab.com/skip-links/#update-3-a-comment-from-gov-uk |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 47 | focusTarget.removeAttribute('tabindex'); |
Derick Montague | 75b4832 | 2019-12-06 01:24:41 -0600 | [diff] [blame] | 48 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 49 | }, |
Yoshie Muranaka | eb154bb | 2020-02-07 12:18:45 -0800 | [diff] [blame] | 50 | }, |
Yoshie Muranaka | 6f71284 | 2021-02-04 11:23:03 -0800 | [diff] [blame^] | 51 | mounted() { |
| 52 | this.$root.$on('refresh-application', () => this.refresh()); |
| 53 | }, |
Yoshie Muranaka | eb154bb | 2020-02-07 12:18:45 -0800 | [diff] [blame] | 54 | methods: { |
| 55 | refresh() { |
| 56 | // Changing the component :key value will trigger |
| 57 | // a component re-rendering and 'refresh' the view |
| 58 | this.routerKey += 1; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 59 | }, |
| 60 | }, |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 61 | }; |
| 62 | </script> |
| 63 | |
| 64 | <style lang="scss" scoped> |
Yoshie Muranaka | 74f8687 | 2020-02-10 12:28:37 -0800 | [diff] [blame] | 65 | .app-container { |
| 66 | display: grid; |
| 67 | grid-template-columns: 100%; |
| 68 | grid-template-rows: auto; |
| 69 | grid-template-areas: |
| 70 | 'header' |
| 71 | 'content'; |
| 72 | |
| 73 | @include media-breakpoint-up($responsive-layout-bp) { |
| 74 | grid-template-columns: $navigation-width 1fr; |
| 75 | grid-template-areas: |
| 76 | 'header header' |
| 77 | 'navigation content'; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | .app-header { |
| 82 | grid-area: header; |
| 83 | position: sticky; |
| 84 | top: 0; |
| 85 | z-index: $zindex-fixed + 1; |
| 86 | } |
| 87 | |
| 88 | .app-navigation { |
| 89 | grid-area: navigation; |
| 90 | } |
| 91 | |
| 92 | .app-content { |
| 93 | grid-area: content; |
| 94 | background-color: $white; |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 95 | } |
| 96 | </style> |