Skip to content

Commit

Permalink
Accessibility improvements and clean code for back-to-top
Browse files Browse the repository at this point in the history
  • Loading branch information
albinazs committed Aug 8, 2023
1 parent e9be249 commit 74c1bc0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/css/explorer-1.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/explorer-1.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/js/components/_BackToTop.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const initBackToTop = (backToTop) => {
const backToTopBtn = backToTop.querySelector('button')
const threshold = parseFloat(backToTop.dataset.threshold) || 300
const scrollTo = parseFloat(backToTop.dataset.scrollto) || 0
const alwaysVisible = backToTop.dataset.alwaysvisible === 'true'
const alwaysVisible = backToTop.dataset.alwaysvisible

const debounce = (func, wait = 0) => {
let timeoutId
Expand Down
8 changes: 5 additions & 3 deletions src/scss/components/_BackToTop.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
@media print {
@apply hidden;
}
}

&.always-visible {
&[data-alwaysvisible] {
> button {
@apply block;
}
}
Expand All @@ -20,10 +22,10 @@
}

.label-text {
@apply hidden;
@apply sr-only;

@screen sm {
@apply block;
@apply not-sr-only;
}
}
}
6 changes: 4 additions & 2 deletions storybook/stories/components/BackToTop/BackToTop.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ export const BackToTopTemplate = ({
scrollTo = '',
buttonClass = '',
}) => {
return `<div class="BackToTop" data-alwaysvisible=${alwaysVisible} data-threshold="${threshold}" data-scrollto="${scrollTo}">
return `<div class="BackToTop" ${
alwaysVisible ? 'data-alwaysvisible' : ''
} data-threshold="${threshold}" data-scrollto="${scrollTo}">
${BaseButtonTemplate({
variant: 'primary',
cssClass: `z-60 ${alwaysVisible ? 'always-visible' : ''}
cssClass: `z-60
${buttonClass ? buttonClass : ''}`,
compact: true,
icon: 'dropdown',
Expand Down

0 comments on commit 74c1bc0

Please sign in to comment.