Skip to content

Commit

Permalink
add keyboard focus to scroll top and remove wording to keep one button (
Browse files Browse the repository at this point in the history
  • Loading branch information
gracepark authored Jan 31, 2022
1 parent 26829bb commit 934b255
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions components/sidebar/SidebarNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const SidebarNav = () => {
role="banner"
>
<div
tabIndex={-1}
className="d-flex flex-items-center p-4 position-sticky top-0 color-bg-default"
style={{ zIndex: 3 }}
id="github-logo"
Expand Down
21 changes: 10 additions & 11 deletions components/ui/ScrollButton/ScrollButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useState, useEffect } from 'react'
import cx from 'classnames'
import { ChevronUpIcon } from '@primer/octicons-react'
import { useTranslation } from '../../hooks/useTranslation'

export type ScrollButtonPropsT = {
className?: string
Expand All @@ -10,7 +9,6 @@ export type ScrollButtonPropsT = {

export const ScrollButton = ({ className, ariaLabel }: ScrollButtonPropsT) => {
const [show, setShow] = useState(false)
const { t } = useTranslation(['scroll_button'])

useEffect(() => {
// show scroll button only when view is scrolled down
Expand All @@ -30,20 +28,21 @@ export const ScrollButton = ({ className, ariaLabel }: ScrollButtonPropsT) => {
}, [])

const onClick = () => {
window.scrollTo({ top: 0, behavior: 'smooth' })
window.scrollTo(0, 0)
const topOfPage = document.getElementById('github-logo')
if (topOfPage) topOfPage.focus()
}

return (
<div className={cx(className, 'transition-200', show ? 'opacity-100' : 'opacity-0')}>
<div
role="tooltip"
className={cx(className, 'transition-200', show ? 'opacity-100' : 'opacity-0')}
>
<button
onClick={onClick}
className="color-bg-default color-fg-default border-0 d-inline-block mr-2 f6"
>
{t('scroll_to_top')}
</button>
<button
onClick={onClick}
className={cx('color-bg-accent-emphasis color-fg-on-emphasis circle border-0')}
className={cx(
'tooltipped tooltipped-n tooltipped-no-delay color-bg-accent-emphasis color-fg-on-emphasis circle border-0'
)}
style={{ width: 40, height: 40 }}
aria-label={ariaLabel}
>
Expand Down

0 comments on commit 934b255

Please sign in to comment.