Skip to content

Commit

Permalink
Fixed #377
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici authored and Çağatay Çivici committed Jul 3, 2018
1 parent 465e813 commit 38adb83
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/components/sidebar/Sidebar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface SidebarProps {
fullScreen?: boolean;
blockScroll?: boolean;
baseZIndex?: number;
dismissable?: boolean;
showCloseIcon?: boolean;
onShow?(): void;
onHide(): void;
}
Expand Down
42 changes: 34 additions & 8 deletions src/components/sidebar/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export class Sidebar extends Component {
fullScreen: false,
blockScroll: false,
baseZIndex: 0,
dismissable: true,
showCloseIcon: true,
onShow: null,
onHide: null
};
Expand All @@ -27,6 +29,8 @@ export class Sidebar extends Component {
fullScreen: PropTypes.bool,
blockScroll: PropTypes.bool,
baseZIndex: PropTypes.number,
dismissable: PropTypes.bool,
showCloseIcon: PropTypes.bool,
onShow: PropTypes.func,
onHide: PropTypes.func.isRequired
};
Expand Down Expand Up @@ -70,11 +74,12 @@ export class Sidebar extends Component {
this.mask = document.createElement('div');
this.mask.style.zIndex = String(parseInt(this.container.style.zIndex, 10) - 1);
DomHandler.addMultipleClasses(this.mask, 'ui-widget-overlay ui-sidebar-mask');
this.maskClickListener = (event) => {
this.onCloseClick(event);
};
this.mask.addEventListener('click', this.maskClickListener);
if (this.props.dismissable) {
this.bindMaskClickListener();
}

document.body.appendChild(this.mask);

if (this.props.blockScroll) {
DomHandler.addClass(document.body, 'ui-overflow-hidden');
}
Expand All @@ -85,7 +90,7 @@ export class Sidebar extends Component {
if (this.mask) {
this.unbindMaskClickListener();
document.body.removeChild(this.mask);
if(this.props.blockScroll) {
if (this.props.blockScroll) {
DomHandler.removeClass(document.body, 'ui-overflow-hidden');
}
this.mask = null;
Expand All @@ -102,22 +107,43 @@ export class Sidebar extends Component {
this.disableModality();
}

bindMaskClickListener() {
if (!this.maskClickListener) {
this.maskClickListener = (event) => {
this.onCloseClick(event);
};
this.mask.addEventListener('click', this.maskClickListener);
}
}

unbindMaskClickListener() {
if (this.maskClickListener) {
this.mask.removeEventListener('click', this.maskClickListener);
this.maskClickListener = null;
}
}

renderCloseIcon() {
if (this.props.showCloseIcon) {
return (
<a className="ui-sidebar-close ui-corner-all" role="button" onClick={this.onCloseClick}>
<span className="pi pi-times"/>
</a>
);
}
else {
return null;
}
}

render() {
const className = classNames('ui-sidebar ui-widget ui-widget-content ui-shadow', this.props.className, 'ui-sidebar-' + this.props.position,
{'ui-sidebar-active': this.props.visible, 'ui-sidebar-full': this.props.fullScreen});
const closeIcon = this.renderCloseIcon();

return (
<div ref={(el) => this.container=el} id={this.props.id} className={className} style={this.props.style}>
<a className="ui-sidebar-close ui-corner-all" role="button" onClick={this.onCloseClick}>
<span className="pi pi-times"/>
</a>
{closeIcon}
{this.props.children}
</div>
);
Expand Down
12 changes: 12 additions & 0 deletions src/showcase/sidebar/SidebarDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ import {Sidebar} from 'primereact/sidebar';
<td>0</td>
<td>Base zIndex value to use in layering.</td>
</tr>
<tr>
<td>dismissable</td>
<td>boolean</td>
<td>true</td>
<td>Whether clicking outside closes the panel.</td>
</tr>
<tr>
<td>showCloseIcon</td>
<td>boolean</td>
<td>true</td>
<td>Whether to display a close icon inside the panel.</td>
</tr>
</tbody>
</table>
</div>
Expand Down

0 comments on commit 38adb83

Please sign in to comment.