Skip to content

Commit

Permalink
Merge pull request #40 from ymrl/a11y_check_practice_2024
Browse files Browse the repository at this point in the history
👍 accessibility check practice 2024
  • Loading branch information
ymrl committed Jun 5, 2024
2 parents 94ec05a + 0322730 commit 102b2ef
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 65 deletions.
8 changes: 5 additions & 3 deletions src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ export const LayoutFunc: React.ForwardRefRenderFunction<
HTMLElement,
{ pathname: string; children: ReactNode }
> = ({ children, pathname }, ref) => {
const mainAs = pathname.match(/^\/?landmark\/no-main\/?/)
? 'section'
: 'main';
const mainAs =
pathname.match(/^\/?landmark\/no-main\/?/) ||
pathname.match(/^\/?practice\/?$/)
? 'section'
: 'main';
return (
<>
<Head>
Expand Down
63 changes: 28 additions & 35 deletions src/components/examples/ErrorField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { TextField, FormItem, FormLabel, Button, P } from '../parts';
import styled from 'styled-components';
import { styled } from 'styled-components';

const ErrorMessage = styled(P)`
color: #dc1e32;
Expand All @@ -14,39 +14,32 @@ export const FieldWithBadErrorMessage = ({
const [message, setMessage] = React.useState('');

return (
<form
onSubmit={(e) => {
/* no-op */
e.preventDefault();
}}
>
<FormItem style={{ marginTop: '1rem' }}>
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label>
<FormLabel>郵便番号</FormLabel>
<TextField
type="text"
value={value}
onChange={(e) => setValue(e.target.value)}
placeholder="141-0032"
aria-label={fieldAriaLabel}
/>
</label>
<Button
type="button"
style={{ marginLeft: '1rem' }}
onClick={() =>
setMessage(
!value.match(/^[0-9]{3}-[0-9]{4}$/)
? '入力形式が正しくありません'
: ''
)
}
>
入力内容の確認
</Button>
{message && <ErrorMessage>{message}</ErrorMessage>}
</FormItem>
</form>
<FormItem style={{ marginTop: '1rem' }}>
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label>
<FormLabel>郵便番号</FormLabel>
<TextField
type="text"
value={value}
onChange={(e) => setValue(e.target.value)}
placeholder="141-0032"
aria-label={fieldAriaLabel}
/>
</label>
<Button
type="button"
style={{ marginLeft: '1rem' }}
onClick={() =>
setMessage(
!value.match(/^[0-9]{3}-[0-9]{4}$/)
? '入力形式が正しくありません'
: ''
)
}
>
入力内容の確認
</Button>
{message && <ErrorMessage>{message}</ErrorMessage>}
</FormItem>
);
};
70 changes: 43 additions & 27 deletions src/pages/practice/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ import * as React from 'react';
import { Title } from '../../components/Title';
import {
Button,
CheckBox,
FormItem,
FormLabel,
H2,
H3,
H4,
IconButton,
Li,
ModalDialog,
P,
RadioButton,
TextField,
TextLink,
Ul,
} from '../../components/parts';
import { NoLabel } from '../../components/examples/form';
import { publicPath } from '../../utils/publicPath';
import {
MdAdd,
Expand All @@ -28,9 +29,7 @@ import {
ExampleContainer,
FieldWithBadErrorMessage,
} from '../../components/examples';
import styled from 'styled-components';

const modalDelay = 5;
import { styled } from 'styled-components';

const SmallButton = styled.button`
width: 1rem;
Expand Down Expand Up @@ -59,6 +58,10 @@ const SmallButton = styled.button`
}
`;

const GrayText = styled.p`
color: #999;
`;

const Practice = (): JSX.Element => {
React.useEffect(() => {
const html = document.getElementsByTagName('html')[0];
Expand All @@ -84,28 +87,10 @@ const Practice = (): JSX.Element => {
| 'overseas'
>();
const [counter, setCounter] = React.useState(12345);
const [modalOpen, setModalOpen] = React.useState(false);
const intervalRef = React.useRef<NodeJS.Timeout | null>(null);
React.useEffect(() => {
if (!intervalRef.current) {
intervalRef.current = setTimeout(() => {
setModalOpen(true);
}, modalDelay * 1000);
}
return () => {
if (intervalRef.current) {
clearTimeout(intervalRef.current);
}
};
}, []);

return (
<>
<Title>アクセシビリティチェックの練習ページ</Title>
<ModalDialog open={modalOpen} onClose={() => setModalOpen(false)}>
<H2>見てくれてありがとう</H2>
<P>閲覧しはじめて{modalDelay}秒経ちました</P>
</ModalDialog>

<H2>アクセシビリティチェックの練習ページ</H2>
<P>
Expand Down Expand Up @@ -197,11 +182,34 @@ const Practice = (): JSX.Element => {
</ExampleContainer>

<H3 as="h4">フォーム</H3>
<NoLabel />
<ExampleContainer>
<FieldWithBadErrorMessage fieldAriaLabel="ご住所" />
</ExampleContainer>
<ExampleContainer>
<FormItem>
<label htmlFor="name">
<FormLabel>氏名</FormLabel>
</label>
<TextField type="text" />
<GrayText>姓と名の間には全角スペースを入れてください</GrayText>
</FormItem>
<FormItem>
<FormLabel>メールアドレス</FormLabel>
<TextField type="email" id="name" />
</FormItem>
<FormItem>
<fieldset>
<legend>
<FormLabel>性別</FormLabel>
</legend>
<RadioButton name="sex" value="1">
男性
</RadioButton>
<RadioButton name="sex" value="2">
女性
</RadioButton>
<RadioButton name="sex" value="9">
その他
</RadioButton>
</fieldset>
</FormItem>
<FormItem>
<fieldset>
<legend>年代</legend>
Expand Down Expand Up @@ -372,6 +380,14 @@ const Practice = (): JSX.Element => {
</RadioButton>
</fieldset>
</FormItem>
<FormItem>
<CheckBox name="toc" value="agree">
利用規約に同意する
</CheckBox>
</FormItem>
</ExampleContainer>
<ExampleContainer>
<FieldWithBadErrorMessage fieldAriaLabel="postal-code" />
</ExampleContainer>
<div style={{ marginTop: '1rem' }}>
<Button
Expand Down

0 comments on commit 102b2ef

Please sign in to comment.