Skip to content

Commit

Permalink
Fixes glennflanagan#99 and adds wrapper around trigger and "non click…
Browse files Browse the repository at this point in the history
…able trigger" for styling possibility.
  • Loading branch information
Ludwig Hubert committed Apr 24, 2020
1 parent 2513ce9 commit dfd7513
Showing 1 changed file with 24 additions and 20 deletions.
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

0 comments on commit dfd7513

Please sign in to comment.