Skip to content
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
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface CollapsibleProps extends React.HTMLProps<Collapsible> {
| "inherit"
| "initial"
| "unset";
triggerSibling?: React.ReactElement<any>;
triggerSibling?: string | React.ReactElement<any> | function;
className?: string;
tabIndex?: number;
contentContainerTagName?: string;
Expand Down
44 changes: 24 additions & 20 deletions src/Collapsible.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ class Collapsible extends Component {
return (
<span className={`${this.props.classParentString}__trigger-sibling`}>{this.props.triggerSibling}</span>
)
} else if (this.props.triggerSibling) {
return <this.props.triggerSibling />
} else if (typeof this.props.triggerSibling === 'object') {
return this.props.triggerSibling
} else if (typeof this.props.triggerSibling === 'function') {
return <this.props.triggerSibling />
}

return null;
}

Expand Down Expand Up @@ -179,6 +180,7 @@ class Collapsible extends Component {
&& !this.state.inTransition ? null : this.props.children;

// Construct CSS classes strings
const headerClassString = `${this.props.classParentString}__header`;
const triggerClassString = `${this.props.classParentString}__trigger ${openClass} ${disabledClass} ${
this.state.isClosed ? this.props.triggerClassName : this.props.triggerOpenedClassName
}`;
Expand All @@ -190,23 +192,25 @@ class Collapsible extends Component {

return (
<ContentContainerElement className={parentClassString.trim()} {...this.props.containerElementProps} >
<TriggerElement
className={triggerClassString.trim()}
onClick={this.handleTriggerClick}
style={this.props.triggerStyle && this.props.triggerStyle}
onKeyPress={(event) => {
const { key } = event;
if (key === ' ' || key === 'Enter') {
this.handleTriggerClick(event);
}
}}
tabIndex={this.props.tabIndex && this.props.tabIndex}
{...this.props.triggerElementProps}
>
{trigger}
</TriggerElement>

{this.renderNonClickableTriggerElement()}
<div className={headerClassString}>
<TriggerElement
className={triggerClassString.trim()}
onClick={this.handleTriggerClick}
style={this.props.triggerStyle && this.props.triggerStyle}
onKeyPress={(event) => {
const { key } = event;
if (key === ' ' || key === 'Enter') {
this.handleTriggerClick(event);
}
}}
tabIndex={this.props.tabIndex && this.props.tabIndex}
{...this.props.triggerElementProps}
>
{trigger}
</TriggerElement>

{this.renderNonClickableTriggerElement()}
</div>

<div
className={outerClassString.trim()}
Expand Down