UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

45 lines 2.33 kB
import * as tslib_1 from "tslib"; import * as React from 'react'; import { DefaultButton } from 'office-ui-fabric-react/lib/Button'; import { Panel, PanelType } from 'office-ui-fabric-react/lib/Panel'; import { Toggle } from 'office-ui-fabric-react/lib/Toggle'; var PanelPreventDefaultExample = /** @class */ (function (_super) { tslib_1.__extends(PanelPreventDefaultExample, _super); function PanelPreventDefaultExample(props) { var _this = _super.call(this, props) || this; _this.onKeyDown = function (ev) { if (ev.keyCode === 27 /* escape */) { ev.preventDefault(); ev.stopPropagation(); } }; _this.toggleAllowEsc = function () { _this.setState({ allowEsc: !_this.state.allowEsc }); }; _this.onDismiss = function (ev) { if (ev && ev.keyCode === 27 /* escape */ && !_this.state.allowEsc) { ev.preventDefault(); return; } _this.setState({ showPanel: false }); }; _this.state = { showPanel: false, allowEsc: true }; return _this; } PanelPreventDefaultExample.prototype.render = function () { var _this = this; return (React.createElement("div", null, React.createElement(DefaultButton, { secondaryText: "Opens the Sample Panel", // tslint:disable-next-line:jsx-no-lambda onClick: function () { return _this.setState({ showPanel: true }); }, text: "Open Panel" }), React.createElement(Panel, { isOpen: this.state.showPanel, type: PanelType.smallFixedNear, // tslint:disable-next-line:jsx-no-lambda onDismiss: this.onDismiss, headerText: "Panel" }, React.createElement("div", null, "Hitting escape inside the text area will not close the Panel"), React.createElement("textarea", { onKeyDown: this.onKeyDown }), React.createElement(Toggle, { checked: this.state.allowEsc, onChange: this.toggleAllowEsc, label: "Allow ESC key to close panel" })))); }; return PanelPreventDefaultExample; }(React.Component)); export { PanelPreventDefaultExample }; //# sourceMappingURL=Panel.PreventDefault.Example.js.map