UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

47 lines 2.29 kB
import * as tslib_1 from "tslib"; import { KeyCodes } from 'office-ui-fabric-react/lib/Utilities'; 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'; import * as React from 'react'; var PanelPreventDefaultExample = /** @class */ (function (_super) { tslib_1.__extends(PanelPreventDefaultExample, _super); function PanelPreventDefaultExample() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.state = { showPanel: false, allowEsc: true }; _this._onKeyDown = function (ev) { if (ev.keyCode === KeyCodes.escape) { ev.preventDefault(); ev.stopPropagation(); } }; _this._toggleAllowEsc = function () { _this.setState({ allowEsc: !_this.state.allowEsc }); }; _this._hidePanel = function (ev) { if (ev && ev.keyCode === KeyCodes.escape && !_this.state.allowEsc) { ev.preventDefault(); return; } _this.setState({ showPanel: false }); }; _this._showPanel = function () { _this.setState({ showPanel: true }); }; return _this; } PanelPreventDefaultExample.prototype.render = function () { return (React.createElement("div", null, React.createElement(DefaultButton, { secondaryText: "Opens the Sample Panel", onClick: this._showPanel, text: "Open Panel" }), React.createElement(Panel, { isOpen: this.state.showPanel, type: PanelType.smallFixedNear, onDismiss: this._hidePanel, 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