-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ハンバーガーメニューを開くボタンのaria-controlsの出力を調整 #423
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { CSS_COLOR, CSS_SIZE } from '@Constants/style' | |
import { LoginContext } from '@Context/LoginContext' | ||
import { useLocation } from '@reach/router' | ||
import { Link as LinkComponent } from 'gatsby' | ||
import React, { FC, useContext, useState } from 'react' | ||
import React, { FC, useContext, useEffect, useState } from 'react' | ||
import { AnchorButton, Cluster, FaBarsIcon, FaSearchIcon, defaultColor, Dialog as shrDialog } from 'smarthr-ui' | ||
import styled, { createGlobalStyle, css } from 'styled-components' | ||
|
||
|
@@ -23,9 +23,14 @@ type Props = { | |
export const Header: FC<Props> = ({ isIndex = false }) => { | ||
const location = useLocation() | ||
const [isOpen, setIsOpen] = useState(false) | ||
const [isClient, setIsClient] = useState(false) | ||
|
||
const { loginStatus, loginLabel } = useContext(LoginContext) | ||
|
||
useEffect(() => { | ||
setIsClient(typeof window !== 'undefined') | ||
}, []) | ||
|
||
const isCurrent = (url: string) => { | ||
const regexp = new RegExp(`${url}`) | ||
const pathname = location.pathname | ||
|
@@ -68,17 +73,19 @@ export const Header: FC<Props> = ({ isIndex = false }) => { | |
</ul> | ||
<MenuContainer> | ||
<StyledOpenButton | ||
// サーバー時は対象となるDialogコンポーネントをレンダリングできないため、aria-controlsは出力しない | ||
{...(isClient && { 'aria-controls': 'panel-menu' })} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここはわざわざuseStateとuseEffect使わないと駄目なんだでしょうか? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tomof |
||
type="button" | ||
onClick={() => { | ||
setIsOpen(true) | ||
}} | ||
title="メニューを開く" | ||
aria-haspopup="true" | ||
aria-controls="panel-menu" | ||
> | ||
<FaBarsIcon size={24} /> | ||
</StyledOpenButton> | ||
{typeof window !== 'undefined' ? ( | ||
{/* サーバー時は`document`が存在せずエラーになるため、Dialogコンポーネントをレンダリングしない */} | ||
{isClient ? ( | ||
<Dialog | ||
isOpen={isOpen} | ||
top={0} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
algoliaの設定のようですが、今回の問題に関係ありますか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
すみません、別の問題なので一旦戻します。