Skip to content

Commit b1fc57f

Browse files
Replace divs with button
1 parent c9aded3 commit b1fc57f

File tree

6 files changed

+18
-11
lines changed

6 files changed

+18
-11
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ import 'react-accessible-accordion/dist/fancy-example.css';
8383
We recommend that you copy them into your own app and modify them to suit your
8484
needs, particularly if you're using your own `className`s.
8585
86+
The accordian trigger is built using native button elements which have default
87+
browser styling, this can be overridden in your stylesheet.
88+
8689
## Component API
8790
8891
### Accordion
@@ -225,8 +228,8 @@ description, as written above. By "accordion-like", we mean components which
225228
have collapsible items but require bespoke interactive mechanisms in order to
226229
expand, collapse and 'disable' them. This includes (but is not limited to)
227230
multi-step forms, like those seen in many cart/checkout flows, which we believe
228-
require (other) complex markup in order to be considered 'accessible'.
229-
This also includes disclosure widgets.
231+
require (other) complex markup in order to be considered 'accessible'. This also
232+
includes disclosure widgets.
230233
231234
### How do I disable an item?
232235

demo/src/main.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ footer {
139139
display: inline-block;
140140
padding: 10px 0;
141141
color: var(--colorPageLinks);
142+
background-color: transparent;
143+
font: inherit;
144+
border: none;
142145
text-decoration: underline solid var(--colorGreenShadow);
143146
}
144147
.code__button:hover {

src/components/AccordionItemButton.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import {
77
focusPreviousSiblingOf,
88
} from '../helpers/focus';
99
import keycodes from '../helpers/keycodes';
10-
import { DivAttributes } from '../helpers/types';
10+
import { ButtonAttributes } from '../helpers/types';
1111
import { assertValidHtmlId } from '../helpers/uuid';
1212

1313
import { Consumer as ItemConsumer, ItemContext } from './ItemContext';
1414

15-
type Props = DivAttributes & {
15+
type Props = ButtonAttributes & {
1616
toggleExpanded(): void;
1717
};
1818

@@ -21,7 +21,9 @@ const AccordionItemButton = ({
2121
className = 'accordion__button',
2222
...rest
2323
}: Props) => {
24-
const handleKeyPress = (evt: React.KeyboardEvent<HTMLDivElement>): void => {
24+
const handleKeyPress = (
25+
evt: React.KeyboardEvent<HTMLButtonElement>,
26+
): void => {
2527
const keyCode = evt.key;
2628

2729
if (
@@ -74,10 +76,9 @@ const AccordionItemButton = ({
7476
}
7577

7678
return (
77-
<div
79+
<button
7880
className={className}
7981
{...rest}
80-
role="button"
8182
tabIndex={0}
8283
onClick={toggleExpanded}
8384
onKeyDown={handleKeyPress}
@@ -87,8 +88,8 @@ const AccordionItemButton = ({
8788
};
8889

8990
type WrapperProps = Pick<
90-
DivAttributes,
91-
Exclude<keyof DivAttributes, keyof InjectedButtonAttributes>
91+
ButtonAttributes,
92+
Exclude<keyof ButtonAttributes, keyof InjectedButtonAttributes>
9293
>;
9394

9495
const AccordionItemButtonWrapper: React.SFC<WrapperProps> = (

src/css/fancy-example.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
width: 100%;
2121
text-align: left;
2222
border: none;
23+
font: inherit;
2324
}
2425

2526
.accordion__button:hover {

src/helpers/AccordionStore.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export interface InjectedButtonAttributes {
1717
'aria-controls': string;
1818
'aria-expanded': boolean;
1919
'aria-disabled': boolean;
20-
role: string;
2120
tabIndex: number;
2221
}
2322

@@ -115,7 +114,6 @@ export default class AccordionStore {
115114
'aria-disabled': disabled,
116115
'aria-expanded': expanded,
117116
'aria-controls': this.getPanelId(uuid),
118-
role: 'button',
119117
tabIndex: 0,
120118
};
121119
};

src/helpers/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import * as React from 'react';
22

33
export type DivAttributes = React.HTMLAttributes<HTMLDivElement>;
4+
export type ButtonAttributes = React.HTMLAttributes<HTMLButtonElement>;

0 commit comments

Comments
 (0)