-
Notifications
You must be signed in to change notification settings - Fork 135
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
Add keyboard support. #84
Changes from 2 commits
8f9d4f0
f6bc528
a31144c
657c991
7fbf41e
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 |
---|---|---|
|
@@ -5,12 +5,25 @@ import PanelContent from './PanelContent'; | |
import Animate from 'rc-animate'; | ||
|
||
class CollapsePanel extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.handleItemClick = this.handleItemClick.bind(this); | ||
this.handleKeyPress = this.handleKeyPress.bind(this); | ||
} | ||
|
||
handleItemClick() { | ||
if (this.props.onItemClick) { | ||
this.props.onItemClick(); | ||
} | ||
} | ||
|
||
handleKeyPress(e) { | ||
e.preventDefault(); | ||
if (e.charCode === 13 || e.charCode === 32) { | ||
this.handleItemClick(); | ||
} | ||
} | ||
|
||
render() { | ||
const { | ||
className, | ||
|
@@ -24,6 +37,7 @@ class CollapsePanel extends Component { | |
showArrow, | ||
destroyInactivePanel, | ||
disabled, | ||
accordion, | ||
forceRender, | ||
} = this.props; | ||
const headerCls = classNames(`${prefixCls}-header`, { | ||
|
@@ -35,12 +49,14 @@ class CollapsePanel extends Component { | |
[`${prefixCls}-item-disabled`]: disabled, | ||
}, className); | ||
return ( | ||
<div className={itemCls} style={style} id={id} role="tablist"> | ||
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. Why remove 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. I just moved it down to an inner div, since what we want to focus would be the header instead of the whole panel. |
||
<div className={itemCls} style={style} id={id} > | ||
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. - id={id} >
+ id={id}> |
||
<div | ||
className={headerCls} | ||
onClick={this.handleItemClick.bind(this)} | ||
role="tab" | ||
onClick={this.handleItemClick} | ||
role={accordion ? 'tab' : 'button'} | ||
tabIndex={disabled ? -1 : 0} | ||
aria-expanded={isActive} | ||
onKeyPress={this.handleKeyPress} | ||
> | ||
{showArrow && <i className="arrow" />} | ||
{header} | ||
|
@@ -56,6 +72,7 @@ class CollapsePanel extends Component { | |
isActive={isActive} | ||
destroyInactivePanel={destroyInactivePanel} | ||
forceRender={forceRender} | ||
role={accordion ? 'tabpanel' : null} | ||
> | ||
{children} | ||
</PanelContent> | ||
|
@@ -86,6 +103,7 @@ CollapsePanel.propTypes = { | |
style: PropTypes.object, | ||
destroyInactivePanel: PropTypes.bool, | ||
disabled: PropTypes.bool, | ||
accordion: PropTypes.bool, | ||
forceRender: PropTypes.bool, | ||
}; | ||
|
||
|
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.
Try
handleItemClick = () => {
instead of binding in constructor.