From 6c69ece25806e5d960d7d64a4d44bbd4db33b3ef Mon Sep 17 00:00:00 2001 From: gopienkonikita Date: Wed, 5 Aug 2020 15:17:21 +0300 Subject: [PATCH] Web: Files: added close events by keys, fixed focus in aside --- .../panels/AddGroupsPanel/AddGroupsPanel.js | 19 ++++++++- .../panels/AddUsersPanel/AddUsersPanel.js | 20 ++++++++- .../panels/OperationsPanel/index.js | 41 +++++++++---------- .../panels/SharingPanel/SharingPanel.js | 22 ++++++++-- .../src/components/panels/StyledPanels.js | 16 ++++++-- 5 files changed, 87 insertions(+), 31 deletions(-) diff --git a/products/ASC.Files/Client/src/components/panels/AddGroupsPanel/AddGroupsPanel.js b/products/ASC.Files/Client/src/components/panels/AddGroupsPanel/AddGroupsPanel.js index 8d4ef68ed1..ec75a912da 100644 --- a/products/ASC.Files/Client/src/components/panels/AddGroupsPanel/AddGroupsPanel.js +++ b/products/ASC.Files/Client/src/components/panels/AddGroupsPanel/AddGroupsPanel.js @@ -20,6 +20,7 @@ class AddGroupsPanelComponent extends React.Component { changeLanguage(i18n); this.state = { showActionPanel: false }; + this.scrollRef = React.createRef(); } onPlusClick = () => @@ -52,6 +53,22 @@ class AddGroupsPanelComponent extends React.Component { onClose(); }; + componentDidMount() { + const scroll = this.scrollRef.current.getElementsByClassName('scroll-body'); + setTimeout(() => scroll[1] && scroll[1].focus(), 2000); + window.addEventListener("keyup", this.onKeyPress); + } + + componentWillUnmount() { + window.removeEventListener("keyup", this.onKeyPress); + } + + onKeyPress = event => { + if (event.key === "Esc" || event.key === "Escape") { + this.props.onClose(); + } + }; + shouldComponentUpdate(nextProps, nextState) { const { showActionPanel } = this.state; const { visible, accessRight } = this.props; @@ -107,7 +124,7 @@ class AddGroupsPanelComponent extends React.Component { /> - + @@ -53,6 +55,22 @@ class AddUsersPanelComponent extends React.Component { onClose(); }; + componentDidMount() { + const scroll = this.scrollRef.current.getElementsByClassName('scroll-body'); + setTimeout(() => scroll[1] && scroll[1].focus(), 2000); + window.addEventListener("keyup", this.onKeyPress); + } + + componentWillUnmount() { + window.removeEventListener("keyup", this.onKeyPress); + } + + onKeyPress = event => { + if (event.key === "Esc" || event.key === "Escape") { + this.props.onClose(); + } + }; + shouldComponentUpdate(nextProps, nextState) { const { showActionPanel } = this.state; const { visible, accessRight } = this.props; @@ -108,7 +126,7 @@ class AddUsersPanelComponent extends React.Component { />*/} - + - - + + } + /> ); } diff --git a/products/ASC.Files/Client/src/components/panels/SharingPanel/SharingPanel.js b/products/ASC.Files/Client/src/components/panels/SharingPanel/SharingPanel.js index ec4642d3b8..e8031e54ec 100644 --- a/products/ASC.Files/Client/src/components/panels/SharingPanel/SharingPanel.js +++ b/products/ASC.Files/Client/src/components/panels/SharingPanel/SharingPanel.js @@ -61,6 +61,7 @@ class SharingPanelComponent extends React.Component { }; this.ref = React.createRef(); + this.scrollRef = React.createRef(); } onPlusClick = () => @@ -186,7 +187,7 @@ class SharingPanelComponent extends React.Component { this.setState({ isNotifyUsers: !this.state.isNotifyUsers }); onShowUsersPanel = () => - this.setState({ showAddUsersPanel: !this.state.showAddUsersPanel }); + this.setState({ showAddUsersPanel: !this.state.showAddUsersPanel, showActionPanel: false }); onFullAccessItemClick = (item) => { const newUsers = this.state.shareDataItems; @@ -438,7 +439,7 @@ class SharingPanelComponent extends React.Component { }); onShowGroupsPanel = () => - this.setState({ showAddGroupsPanel: !this.state.showAddGroupsPanel }); + this.setState({ showAddGroupsPanel: !this.state.showAddGroupsPanel, showActionPanel: false }); onChangeMessage = (e) => this.setState({ message: e.target.value }); @@ -449,12 +450,27 @@ class SharingPanelComponent extends React.Component { componentDidMount() { this.props.onLoading(true); this.getShareData(); + + document.addEventListener("keyup", this.onKeyPress); } + componentWillUnmount() { + document.removeEventListener("keyup", this.onKeyPress); + } + + onKeyPress = event => { + const { showAddUsersPanel, showEmbeddingPanel, showAddGroupsPanel } = this.state; + if(showAddUsersPanel || showEmbeddingPanel || showAddGroupsPanel) return; + if (event.key === "Esc" || event.key === "Escape") { + this.props.onClose(); + } + }; + componentDidUpdate(prevProps, prevState) { if(this.state.showPanel !== prevState.showPanel && this.state.showPanel === false) { this.props.onClose(); } + this.scrollRef.current.view.focus(); } render() { @@ -590,7 +606,7 @@ class SharingPanelComponent extends React.Component { />*/} - + {shareDataItems.map((item, index) => ( (props.visible ? "0" : "500px")}); + width: 500px; + + @media (max-width: 550px) { + width: 320px; + transform: translateX(${(props) => (props.visible ? "0" : "320px")}); + } + } + .header_aside-panel { transform: translateX(${(props) => (props.visible ? "0" : "500px")}); width: 500px; @@ -78,10 +90,6 @@ const StyledContent = styled.div` border-bottom: 1px solid #dee2e6; } - .files-operations-body { - padding: 16px 0; - } - .header_aside-panel-header { max-width: 500px; margin: 0 0 0 16px;