summaryrefslogtreecommitdiff
path: root/src/components/_ibs/Mixins/JumpLinkMixin.js
diff options
context:
space:
mode:
authorAndrey V.Kosteltsev <AKosteltsev@IBS.RU>2022-07-04 23:11:28 +0300
committerAndrey V.Kosteltsev <AKosteltsev@IBS.RU>2022-07-04 23:11:28 +0300
commit3f4094d08b873e17464a51c817ea7d41177f848d (patch)
tree8880a0e7c8c0ac07ed298ce719cfab3278f2aa12 /src/components/_ibs/Mixins/JumpLinkMixin.js
parentf5c8dbfa6fb3812a3b3a2aafd3538fbdf8b8c668 (diff)
downloadwebui-vue-3f4094d08b873e17464a51c817ea7d41177f848d.tar.xz
IBS: _ibs UI Theme
Diffstat (limited to 'src/components/_ibs/Mixins/JumpLinkMixin.js')
-rw-r--r--src/components/_ibs/Mixins/JumpLinkMixin.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/components/_ibs/Mixins/JumpLinkMixin.js b/src/components/_ibs/Mixins/JumpLinkMixin.js
new file mode 100644
index 00000000..b038527b
--- /dev/null
+++ b/src/components/_ibs/Mixins/JumpLinkMixin.js
@@ -0,0 +1,27 @@
+const JumpLinkMixin = {
+ methods: {
+ setFocus(element) {
+ element.setAttribute('tabindex', '-1');
+ element.focus();
+ // Reason: https://axesslab.com/skip-links/#update-3-a-comment-from-gov-uk
+ element.removeAttribute('tabindex');
+ },
+ scrollToOffset(event) {
+ // Select element to scroll to
+ const ref = event.target.getAttribute('data-ref');
+ const element = this.$refs[ref].$el;
+
+ // Set focus and tabindex on selected element
+ this.setFocus(element);
+
+ // Set scroll offset below header
+ const offset = element.offsetTop - 50;
+ window.scroll({
+ top: offset,
+ behavior: 'smooth',
+ });
+ },
+ },
+};
+
+export default JumpLinkMixin;