Skip to content
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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gatsby-plugin-algolia-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@ export const algoliaConfig = {
indexName: process.env.GATSBY_ALGOLIA_INDEX_NAME,
queries: [...mdxQueries, ...airtableQueries],
dryRun: process.env.BRANCH !== 'main',
continueOnFailure: false,
continueOnFailure: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

algoliaの設定のようですが、今回の問題に関係ありますか?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

すみません、別の問題なので一旦戻します。

}
13 changes: 10 additions & 3 deletions src/components/shared/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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
Expand Down Expand Up @@ -68,17 +73,19 @@ export const Header: FC<Props> = ({ isIndex = false }) => {
</ul>
<MenuContainer>
<StyledOpenButton
// サーバー時は対象となるDialogコンポーネントをレンダリングできないため、aria-controlsは出力しない
{...(isClient && { 'aria-controls': 'panel-menu' })}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここはわざわざuseStateとuseEffect使わないと駄目なんだでしょうか?
{...(typeof window !== 'undefined' && { 'aria-controls': 'panel-menu' })} だと動作しないですかね?
出来るだけ、useStateやuseEffectは使わないほうが良いかなと思い。

Copy link
Contributor Author

@yuw27b yuw27b Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomof useEffectでないと、CSRでも出力されないようです。<Dialog>と同じように、<StyledOpenButton>要素ごとtypeof window...で制御するのはできるので、そのほうが良いでしょうか?

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}
Expand Down