Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/dropdown correct display #377

Merged
merged 36 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1fe1136
Web: Components: added portals to drop-down
dmitry-sychugov Sep 13, 2021
009dc5b
Web: Studio: added ref for drop-down
dmitry-sychugov Sep 13, 2021
e6e4955
Merge branch 'release/1.0.0' into bugfix/dropdown-correct-display
dmitry-sychugov Sep 13, 2021
11dfddb
Merge branch 'release/1.0.0' into bugfix/dropdown-correct-display
dmitry-sychugov Sep 14, 2021
15e7cf9
Merge branch 'release/1.0.0' into bugfix/dropdown-correct-display
dmitry-sychugov Sep 16, 2021
19c8ee3
Web: Components: added drop down work in two modes
dmitry-sychugov Oct 5, 2021
3f81f68
Web: Components: fixed people group selector, fixed checkbox table se…
dmitry-sychugov Oct 5, 2021
4a16633
Merge branch 'release/1.0.0' into bugfix/dropdown-correct-display
dmitry-sychugov Oct 5, 2021
b0fe6bd
Merge branch 'release/1.0.0' into bugfix/dropdown-correct-display
ilyaoleshko Oct 7, 2021
554552c
Web: Client: People: Fixed paging displaying, added tReady property.
ilyaoleshko Oct 7, 2021
5f05923
Web: Client: Files: Fixed log displaying inside paging component
ilyaoleshko Oct 7, 2021
c87be7e
Web: Components: Added usage isDefaultMode property for DropDown
ilyaoleshko Oct 7, 2021
b9c3b25
Web: Common: fixed drop down displaying in filter components
dmitry-sychugov Oct 12, 2021
2c8ea76
Web: Common: added missing drop down styles
dmitry-sychugov Oct 12, 2021
1725f40
Web: Common: fixed backdrop width in tablet mode when opened drop down
dmitry-sychugov Oct 12, 2021
be8a28a
Web: Components: fixed displaying drop down
dmitry-sychugov Oct 12, 2021
9984780
Web: Components: fixed drop down width and positioning when there is …
dmitry-sychugov Oct 12, 2021
5ebf750
Web: People: fixed drop down displaying in ContactField components
dmitry-sychugov Oct 12, 2021
6e4e3d6
Merge branch 'release/1.0.0' into bugfix/dropdown-correct-display
dmitry-sychugov Oct 12, 2021
a33f6b9
Web: Components: fixed drop down positioning for drop down without po…
dmitry-sychugov Oct 14, 2021
30bbfd4
Web: Common: fixed drop down in aside mode advanced selector, fixed h…
dmitry-sychugov Oct 14, 2021
bc37fcc
Merge branch 'release/1.0.0' into bugfix/dropdown-correct-display
dmitry-sychugov Oct 14, 2021
ec7f028
Web: Common: switched drop down mode in hideFilter
dmitry-sychugov Oct 14, 2021
d49cd49
Web: Components: changed condition to positioning on right side in dr…
dmitry-sychugov Oct 14, 2021
a6b398d
Web: Components: added onScroll in row container
dmitry-sychugov Oct 15, 2021
732f08a
Web: Files: added closing drop down when we scrolling
dmitry-sychugov Oct 15, 2021
26b06f7
Web: People: fixed language selection drop down
dmitry-sychugov Oct 15, 2021
58fce28
Merge branch 'release/1.0.0' into bugfix/dropdown-correct-display
dmitry-sychugov Oct 15, 2021
7428893
Web: Common, Components, People: added small section prop for drop down
dmitry-sychugov Oct 15, 2021
24ad7bf
Web: Common: fix aside view for people and group selector
dmitry-sychugov Oct 15, 2021
95e30d7
Web: Common: switched filter item to without portal mode, fixed openi…
dmitry-sychugov Oct 18, 2021
51c91cf
Web: Common: fixed user selector when aside panel expanded, corrected…
dmitry-sychugov Oct 18, 2021
5b64a61
Merge branch 'release/1.0.0' into bugfix/dropdown-correct-display
dmitry-sychugov Oct 18, 2021
b393678
Web: Common: fixed user selector
dmitry-sychugov Oct 18, 2021
3a50fca
Merge branch 'hotfix/v1.1.1' into bugfix/dropdown-correct-display
dmitry-sychugov Dec 2, 2021
e60c082
Web: Client: fixed position profile menu drop down
dmitry-sychugov Dec 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class AdvancedSelector extends React.Component {
super(props);

this.ref = React.createRef();

this.state = {
displayType: this.getTypeByWidth(),
};
Expand Down Expand Up @@ -87,15 +86,24 @@ class AdvancedSelector extends React.Component {

render() {
const { displayType } = this.state;
const { isOpen, id, className, style, withoutAside } = this.props;
const {
isOpen,
id,
className,
style,
withoutAside,
isDefaultDisplayDropDown,
} = this.props;

//console.log(`AdvancedSelector render() isOpen=${isOpen} displayType=${displayType}`);

return (
<div ref={this.ref} id={id} className={className} style={style}>
<div id={id} className={className} style={style}>
{displayType === "dropdown" ? (
<DropDown
forwardedRef={this.ref}
open={isOpen}
isDefaultMode={isDefaultDisplayDropDown ? true : false}
className="dropdown-container"
clickOutsideAction={this.onClose}
>
Expand Down Expand Up @@ -157,6 +165,7 @@ AdvancedSelector.propTypes = {
onCancel: PropTypes.func,
onAddNewClick: PropTypes.func,
loadNextPage: PropTypes.func,
isDefaultDisplayDropDown: PropTypes.bool,
};

AdvancedSelector.defaultProps = {
Expand All @@ -168,6 +177,7 @@ AdvancedSelector.defaultProps = {
allowAnyClickClose: true,
displayType: "auto",
options: [],
isDefaultDisplayDropDown: true,
};

export default AdvancedSelector;
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class HideFilter extends React.Component {

<div className="dropdown-style" ref={this.dropDownRef}>
<DropDown
forwardedRef={this.ref}
className="drop-down hide-filter-drop-down"
clickOutsideAction={this.handleClickOutside}
manualY="8px"
Expand Down
4 changes: 4 additions & 0 deletions packages/asc-web-common/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ body {
}
}

.table-container_settings-checkbox {
padding: 8px 16px;
}

body {
margin: 0;
}
Expand Down
13 changes: 10 additions & 3 deletions packages/asc-web-components/combobox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ class ComboBox extends React.Component {
toggleAction,
textOverflow,
showDisabledItems,
isDefaultMode,
} = this.props;
const { isOpen, selectedOption } = this.state;

const dropDownMaxHeightProp = dropDownMaxHeight
? { maxHeight: dropDownMaxHeight }
: {};
const dropDownManualWidthProp = scaledOptions
? { manualWidth: "100%" }

const dropDownManualWidthProp = this.ref.current
? { manualWidth: this.ref.current.clientWidth + "px" }
: {};

const optionsLength = options.length
Expand Down Expand Up @@ -140,10 +142,12 @@ class ComboBox extends React.Component {
directionY={directionY}
manualY="102%"
open={isOpen}
forwardedRef={this.ref}
clickOutsideAction={this.handleClickOutside}
{...dropDownMaxHeightProp}
{...dropDownManualWidthProp}
showDisabledItems={showDisabledItems}
isDefaultMode={isDefaultMode}
>
{advancedOptions
? advancedOptions
Expand Down Expand Up @@ -175,7 +179,7 @@ ComboBox.propTypes = {
/** X direction selection */
directionX: PropTypes.oneOf(["left", "right"]),
/** Y direction selection */
directionY: PropTypes.oneOf(["bottom", "top"]),
directionY: PropTypes.oneOf(["bottom", "top", "both"]),
/** Component Display Type */
displayType: PropTypes.oneOf(["default", "toggle"]),
/** Height of Dropdown */
Expand Down Expand Up @@ -210,6 +214,8 @@ ComboBox.propTypes = {
textOverflow: PropTypes.bool,
/** Disables clicking on the icon */
disableIconClick: PropTypes.bool,
/** Defines the operation mode of the component, by default with the portal */
isDefaultMode: PropTypes.bool,
};

ComboBox.defaultProps = {
Expand All @@ -221,6 +227,7 @@ ComboBox.defaultProps = {
size: "base",
disableIconClick: true,
showDisabledItems: false,
isDefaultMode: true,
};

export default ComboBox;
1 change: 1 addition & 0 deletions packages/asc-web-components/context-menu-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class ContextMenuButton extends React.Component {
directionX={directionX}
directionY={directionY}
open={isOpen}
forwardedRef={this.ref}
clickOutsideAction={this.clickOutsideAction}
columnCount={columnCount}
withBackdrop={!!isMobile}
Expand Down
2 changes: 2 additions & 0 deletions packages/asc-web-components/date-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,11 @@ class DatePicker extends Component {
displayType === "dropdown" ? (
<DropDownStyle>
<DropDown
forwardedRef={this.ref}
className="drop-down"
open={isOpen}
clickOutsideAction={this.onClose}
isDefaultMode={false}
>
{this.renderBody()}
</DropDown>
Expand Down
96 changes: 91 additions & 5 deletions packages/asc-web-components/drop-down/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import PropTypes from "prop-types";
import { VariableSizeList } from "react-window";
import onClickOutside from "react-onclickoutside";
import { isMobile } from "react-device-detect";
import Portal from "../portal";
import DomHelpers from "../utils/domHelpers";

import CustomScrollbarsVirtualList from "../scrollbar/custom-scrollbars-virtual-list";
import DropDownItem from "../drop-down-item";
Expand Down Expand Up @@ -36,26 +38,33 @@ class DropDown extends React.PureComponent {
directionX: props.directionX,
directionY: props.directionY,
};

this.dropDownRef = React.createRef();
}

componentDidMount() {
if (this.props.open) {
this.props.enableOnClickOutside();
this.checkPosition();
if (this.props.isDefaultMode) {
return setTimeout(() => this.checkPositionPortal(), 0); // ditry, but need after render for ref
}
return this.checkPosition();
}
}

componentWillUnmount() {
this.props.disableOnClickOutside();
this.unbindDocumentResizeListener();
}

componentDidUpdate(prevProps) {
if (this.props.open !== prevProps.open) {
if (this.props.open) {
this.props.enableOnClickOutside();
this.checkPosition();
this.bindDocumentResizeListener();
if (this.props.isDefaultMode) {
return this.checkPositionPortal();
}
return this.checkPosition();
} else {
this.props.disableOnClickOutside();
}
Expand All @@ -72,6 +81,29 @@ class DropDown extends React.PureComponent {
this.props.clickOutsideAction(e, !this.props.open);
};

bindDocumentResizeListener() {
if (!this.documentResizeListener) {
this.documentResizeListener = (e) => {
if (this.props.open) {
if (this.props.isDefaultMode) {
this.checkPositionPortal();
} else {
this.checkPosition();
}
}
};

window.addEventListener("resize", this.documentResizeListener);
}
}

unbindDocumentResizeListener() {
if (this.documentResizeListener) {
window.removeEventListener("resize", this.documentResizeListener);
this.documentResizeListener = null;
}
}

checkPosition = () => {
if (!this.dropDownRef.current) return;

Expand All @@ -95,6 +127,46 @@ class DropDown extends React.PureComponent {
});
};

checkPositionPortal = () => {
const parent = this.props.forwardedRef;
const rects = parent.current.getBoundingClientRect();

let dropDownHeight = this.dropDownRef.current.offsetParent
? this.dropDownRef.current.offsetHeight
: DomHelpers.getHiddenElementOuterHeight(this.dropDownRef.current);

let left = rects.left;
let bottom = rects.bottom;

const viewport = DomHelpers.getViewport();
const dropDownRects = this.dropDownRef.current.getBoundingClientRect();

if (
this.props.directionY === "top" ||
(this.props.directionY === "both" &&
rects.bottom + dropDownHeight > viewport.height)
) {
bottom -= parent.current.clientHeight + dropDownHeight;
}

if (this.props.right) {
this.dropDownRef.current.style.right = this.props.right;
} else if (this.props.directionX === "right") {
this.dropDownRef.current.style.left =
rects.right - this.dropDownRef.current.clientWidth + "px";
} else {
this.dropDownRef.current.style.left = left + "px";
}

this.dropDownRef.current.style.top = this.props.top || bottom + "px";

this.setState({
directionX: this.props.directionX,
directionY: this.props.directionY,
width: dropDownRects.width,
});
};

getItemHeight = (item) => {
const isTablet = window.innerWidth < 1024; //TODO: Make some better

Expand Down Expand Up @@ -123,7 +195,7 @@ class DropDown extends React.PureComponent {
}
};

render() {
renderDropDown() {
const { maxHeight, children, showDisabledItems } = this.props;
const { directionX, directionY, width } = this.state;
let cleanChildren;
Expand Down Expand Up @@ -169,6 +241,16 @@ class DropDown extends React.PureComponent {
</StyledDropdown>
);
}
render() {
const { isDefaultMode } = this.props;
const element = this.renderDropDown();

if (isDefaultMode) {
return <Portal element={element} appendTo={this.props.appendTo} />;
}

return element;
}
}

const EnhancedComponent = onClickOutside(DropDown);
Expand Down Expand Up @@ -211,7 +293,7 @@ DropDownContainer.propTypes = {
/** Sets the opening direction relative to the parent */
directionX: PropTypes.oneOf(["left", "right"]), //TODO: make more informative
/** Sets the opening direction relative to the parent */
directionY: PropTypes.oneOf(["bottom", "top"]),
directionY: PropTypes.oneOf(["bottom", "top", "both"]),
/** Accepts id */
id: PropTypes.string,
/** Required if you need to specify the exact width of the component, for example 100% */
Expand All @@ -232,13 +314,17 @@ DropDownContainer.propTypes = {
columnCount: PropTypes.number,
/** Display disabled items or not */
showDisabledItems: PropTypes.bool,
forwardedRef: PropTypes.shape({ current: PropTypes.any }),
/** Defines the operation mode of the component, by default with the portal */
isDefaultMode: PropTypes.bool,
};

DropDownContainer.defaultProps = {
directionX: "left",
directionY: "bottom",
withBackdrop: true,
showDisabledItems: false,
isDefaultMode: true,
};

export default DropDownContainer;
1 change: 1 addition & 0 deletions packages/asc-web-components/group-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class GroupButton extends React.Component {
</Caret>
</StyledDropdownToggle>
<DropDown
forwardedRef={this.ref}
{...dropDownMaxHeightProp}
{...offsetSelectDropDown}
manualY="72px"
Expand Down
1 change: 1 addition & 0 deletions packages/asc-web-components/link-with-dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class LinkWithDropdown extends React.Component {
className="fixed-max-width"
open={this.state.isOpen}
withArrow={false}
forwardedRef={this.ref}
clickOutsideAction={this.onClose}
{...rest}
>
Expand Down
5 changes: 5 additions & 0 deletions packages/asc-web-components/main-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class MainButton extends React.PureComponent {

render() {
//console.log("MainButton render");
const dropDownManualWidthProp = this.ref.current
? { manualWidth: this.ref.current.clientWidth + "px" }
: {};
return (
<GroupMainButton {...this.props} ref={this.ref}>
<StyledMainButton {...this.props} onClick={this.onMainButtonClick}>
Expand All @@ -84,8 +87,10 @@ class MainButton extends React.PureComponent {
</StyledMainButton>
{this.props.isDropdown ? (
<StyledDropDown
forwardedRef={this.ref}
open={this.state.isOpen}
clickOutsideAction={this.handleClick}
{...dropDownManualWidthProp}
{...this.props}
onClick={this.onDropDownClick}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/asc-web-components/paging/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Paging.propTypes = {
/** Items per page combo box items */
countItems: PropTypes.array,
/** Indicates opening direction of combo box */
openDirection: PropTypes.oneOf(["bottom", "top"]),
openDirection: PropTypes.oneOf(["bottom", "top", "both"]),
/** Accepts class */
className: PropTypes.string,
/** Accepts id */
Expand Down
2 changes: 1 addition & 1 deletion packages/asc-web-components/progress-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const ProgressBar = (props) => {
</div>
<div className="progress-bar_field" />
{dropDownContent && (
<DropDown open={isOpen} clickOutsideAction={onClose}>
<DropDown open={isOpen} clickOutsideAction={onClose} forwardedRef={ref}>
<div className="progress-bar_drop-down">{dropDownContent}</div>
</DropDown>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const TableSettings = ({ columns }) => {
directionX="right"
open={isOpen}
clickOutsideAction={clickOutsideAction}
forwardedRef={ref}
withBackdrop={false}
>
{columns.map((column) => {
Expand Down
Loading