Skip to content

feat: add wrappedComponentRef props for get panel dom ref #139

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ If `accordion` is true, only one panel can be open. Opening another panel will
<th></th>
<td>Content to render in the right of the panel header</td>
</tr>
<tr>
<td>wrappedComponentRef</td>
<td>inst => this.ref = inst</td>
<th>null</th>
<td>get panel dom ref</td>
</tr>
</tbody>
</table>

Expand Down
14 changes: 12 additions & 2 deletions src/Panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CollapsePanel extends Component {
forceRender,
expandIcon,
extra,
wrappedComponentRef,
} = this.props;
const headerCls = classNames(`${prefixCls}-header`, {
[headerClass]: headerClass,
Expand All @@ -55,8 +56,16 @@ class CollapsePanel extends Component {
if (showArrow && typeof expandIcon === 'function') {
icon = expandIcon(this.props);
}
const panelProps = {
id,
style,
className: itemCls,
};
if (wrappedComponentRef) {
panelProps.ref = wrappedComponentRef;
}
return (
<div className={itemCls} style={style} id={id}>
<div {...panelProps}>
<div
className={headerCls}
onClick={this.handleItemClick}
Expand All @@ -67,7 +76,7 @@ class CollapsePanel extends Component {
>
{showArrow && icon}
{header}
{extra && (<div className={`${prefixCls}-extra`}>{extra}</div>)}
{extra && <div className={`${prefixCls}-extra`}>{extra}</div>}
</div>
<Animate
showProp="isActive"
Expand Down Expand Up @@ -116,6 +125,7 @@ CollapsePanel.propTypes = {
expandIcon: PropTypes.func,
extra: PropTypes.node,
panelKey: PropTypes.any,
wrappedComponentRef: PropTypes.func,
};

CollapsePanel.defaultProps = {
Expand Down