Skip to content

Commit

Permalink
Fixed #201
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici committed Dec 2, 2017
1 parent f234a67 commit 0d55cf3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
16 changes: 11 additions & 5 deletions src/components/fieldset/Fieldset.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
.ui-fieldset, .ui-fieldset .ui-fieldset-legend {
padding: 0.6em 1em;
.ui-fieldset,
.ui-fieldset .ui-fieldset-legend {
padding: 0.5em 1em;
}

.ui-fieldset-toggleable .ui-fieldset-legend {
padding: 0.5em 1em 0.5em 0.5em;
padding: 0;
}

.ui-fieldset-toggleable .ui-fieldset-legend a {
padding: 0.5em 1em;
cursor:pointer;
white-space: nowrap;
display: block;
}

.ui-fieldset .ui-fieldset-toggler {
Expand All @@ -14,8 +20,8 @@
vertical-align: middle;
}

.ui-fieldset .ui-fieldset-content-wrapper-overflown {
overflow: hidden;
.ui-fieldset .ui-fieldset-legend-text {
vertical-align: middle;
}

.ui-fieldset-content-wrapper-collapsed {
Expand Down
29 changes: 26 additions & 3 deletions src/components/fieldset/Fieldset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, {Component} from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import DomHandler from '../utils/DomHandler';
import UniqueComponentId from '../utils/UniqueComponentId';

export class Fieldset extends Component {

Expand Down Expand Up @@ -33,6 +34,10 @@ export class Fieldset extends Component {
this.toggle = this.toggle.bind(this);
}

componentWillMount() {
this.id = this.props.id || UniqueComponentId();
}

componentDidUpdate() {
if(this.props.toggleable && !this.state.collapsed && this.expanding) {
DomHandler.addClass(this.contentWrapper, 'ui-fieldset-content-wrapper-expanding');
Expand Down Expand Up @@ -83,25 +88,43 @@ export class Fieldset extends Component {
'ui-fieldset-content-wrapper-collapsed': (this.state.collapsed && this.props.toggleable),
'ui-fieldset-content-wrapper-expanded': (!this.state.collapsed && this.props.toggleable)
});
let id = this.id + '_content';

return (
<div ref={(el) => this.contentWrapper = el} className={className}>
<div ref={(el) => this.contentWrapper = el} className={className} id={id} aria-hidden={this.state.collapsed} role="region">
<div className="ui-fieldset-content">
{this.props.children}
</div>
</div>
);
}

renderToggleIcon() {
if(this.props.toggleable) {
let className = classNames('ui-fieldset-toggler fa fa-fw', { 'fa-plus': this.state.collapsed, 'fa-minus': !this.state.collapsed });

return (
<span className={className}></span>
);
}
else {
return null;
}
}

render() {
let content = this.renderContent();
let className = classNames('ui-fieldset ui-widget ui-widget-content ui-corner-all', this.props.className, {'ui-fieldset-toggleable': this.props.toggleable});
let toggleIcon = this.renderToggleIcon();
let ariaControls = this.id + '_content';

return (
<fieldset id={this.props.id} className={className} style={this.props.style}>
<legend className="ui-fieldset-legend ui-corner-all ui-state-default ui-unselectable-text" onClick={this.toggle}>
{this.props.toggleable && <span className={classNames('ui-fieldset-toggler fa fa-fw', {'fa-plus': this.state.collapsed, 'fa-minus': !this.state.collapsed})}></span>}
{this.props.legend}
<a href="#" aria-controls={ariaControls} aria-expanded={!this.state.collapsed} tabIndex={this.props.toggleable ? null : -1}>
{toggleIcon}
<span className="ui-fieldset-legend-text">{this.props.legend}</span>
</a>
</legend>
{content}
</fieldset>
Expand Down

0 comments on commit 0d55cf3

Please sign in to comment.