Fix overflowing multi select widget (#320)
Co-authored-by: Akash N <akash@codemonk.in>
This commit is contained in:
parent
7eac30f82a
commit
bb369e6bdf
|
|
@ -56,6 +56,7 @@ const StyledSingleDropDown = styled(SingleDropDown)`
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
background: white;
|
background: white;
|
||||||
|
min-height: 32px;
|
||||||
}
|
}
|
||||||
.${Classes.BUTTON_TEXT} {
|
.${Classes.BUTTON_TEXT} {
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
|
@ -147,9 +148,20 @@ const DropdownContainer = styled.div`
|
||||||
${BlueprintCSSTransform}
|
${BlueprintCSSTransform}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const StyledMultiDropDown = styled(MultiDropDown)`
|
const StyledCheckbox = styled(Checkbox)`
|
||||||
|
&&.${Classes.CHECKBOX}.${Classes.CONTROL} {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const StyledMultiDropDown = styled(MultiDropDown)<{
|
||||||
|
hideCloseButtonIndex: number;
|
||||||
|
height: number;
|
||||||
|
width: number;
|
||||||
|
}>`
|
||||||
div {
|
div {
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
|
height: ${props => props.height - WIDGET_PADDING * 2}px;
|
||||||
}
|
}
|
||||||
.${MultiSelectClasses.MULTISELECT} {
|
.${MultiSelectClasses.MULTISELECT} {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
@ -164,19 +176,38 @@ const StyledMultiDropDown = styled(MultiDropDown)`
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
min-height: 32px;
|
||||||
|
|
||||||
.${Classes.TAG_INPUT_VALUES} {
|
.${Classes.TAG_INPUT_VALUES} {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
padding: 2px 0;
|
height: ${props => props.height - WIDGET_PADDING * 2 - 2}px;
|
||||||
|
display: initial;
|
||||||
}
|
}
|
||||||
|
|
||||||
.${Classes.TAG} {
|
.${Classes.TAG} {
|
||||||
background: none;
|
background: none;
|
||||||
border: 1px solid #D0D7DD;
|
border: 1px solid #D0D7DD;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
margin-bottom: 0;
|
margin: 3px 2px;
|
||||||
max-width: 100px;
|
max-width: ${props => props.width * 0.85}px;
|
||||||
|
height: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
${props =>
|
||||||
|
props.hideCloseButtonIndex >= 0 &&
|
||||||
|
`
|
||||||
|
.${Classes.TAG}:nth-child(${props.hideCloseButtonIndex}) {
|
||||||
|
.${Classes.ICON} {
|
||||||
|
align-self: center;
|
||||||
|
margin-right: 0px;
|
||||||
|
color: ${Colors.SLATE_GRAY};
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`}
|
||||||
& > .${Classes.ICON} {
|
& > .${Classes.ICON} {
|
||||||
align-self: center;
|
align-self: center;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
|
|
@ -185,24 +216,21 @@ const StyledMultiDropDown = styled(MultiDropDown)`
|
||||||
.${Classes.INPUT_GHOST} {
|
.${Classes.INPUT_GHOST} {
|
||||||
flex: 0 0 auto;
|
flex: 0 0 auto;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
width: 1px;
|
||||||
|
height: 26px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const StyledCheckbox = styled(Checkbox)`
|
|
||||||
&&.${Classes.CHECKBOX}.${Classes.CONTROL} {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
class DropDownComponent extends React.Component<DropDownComponentProps> {
|
class DropDownComponent extends React.Component<DropDownComponentProps> {
|
||||||
render() {
|
render() {
|
||||||
const selectedItems = this.props.selectedIndexArr
|
const { selectedIndexArr, options } = this.props;
|
||||||
? _.map(this.props.selectedIndexArr, index => {
|
const selectedItems = selectedIndexArr
|
||||||
return this.props.options[index];
|
? _.map(selectedIndexArr, index => options[index])
|
||||||
})
|
|
||||||
: [];
|
: [];
|
||||||
|
const hideCloseButtonIndex = -1;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownContainer>
|
<DropdownContainer>
|
||||||
<DropdownStyles />
|
<DropdownStyles />
|
||||||
|
|
@ -256,19 +284,29 @@ class DropDownComponent extends React.Component<DropDownComponentProps> {
|
||||||
tagRenderer={this.renderTag}
|
tagRenderer={this.renderTag}
|
||||||
itemRenderer={this.renderMultiSelectItem}
|
itemRenderer={this.renderMultiSelectItem}
|
||||||
selectedItems={selectedItems}
|
selectedItems={selectedItems}
|
||||||
|
height={this.props.height}
|
||||||
tagInputProps={{
|
tagInputProps={{
|
||||||
onRemove: this.onItemRemoved,
|
onRemove: this.onItemRemoved,
|
||||||
tagProps: { minimal: true },
|
tagProps: (value, index) => ({
|
||||||
// inputProps: { readOnly: true },
|
minimal: true,
|
||||||
|
interactive:
|
||||||
|
hideCloseButtonIndex - 1 === index ? true : false,
|
||||||
|
rightIcon:
|
||||||
|
hideCloseButtonIndex - 1 === index
|
||||||
|
? IconNames.CHEVRON_DOWN
|
||||||
|
: undefined,
|
||||||
|
}),
|
||||||
disabled: this.props.disabled,
|
disabled: this.props.disabled,
|
||||||
rightElement: <Icon icon={IconNames.CHEVRON_DOWN} />,
|
rightElement: <Icon icon={IconNames.CHEVRON_DOWN} />,
|
||||||
}}
|
}}
|
||||||
|
hideCloseButtonIndex={hideCloseButtonIndex}
|
||||||
onItemSelect={this.onItemSelect}
|
onItemSelect={this.onItemSelect}
|
||||||
popoverProps={{
|
popoverProps={{
|
||||||
minimal: true,
|
minimal: true,
|
||||||
usePortal: true,
|
usePortal: true,
|
||||||
popoverClassName: "select-popover-wrapper",
|
popoverClassName: "select-popover-wrapper",
|
||||||
}}
|
}}
|
||||||
|
width={this.props.width}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</StyledControlGroup>
|
</StyledControlGroup>
|
||||||
|
|
@ -367,6 +405,8 @@ export interface DropDownComponentProps extends ComponentProps {
|
||||||
selectedIndexArr: number[];
|
selectedIndexArr: number[];
|
||||||
options: DropdownOption[];
|
options: DropdownOption[];
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default DropDownComponent;
|
export default DropDownComponent;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
|
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
|
||||||
import { WidgetType } from "constants/WidgetConstants";
|
import { WidgetType, WIDGET_PADDING } from "constants/WidgetConstants";
|
||||||
import { EventType } from "constants/ActionConstants";
|
import { EventType } from "constants/ActionConstants";
|
||||||
import DropDownComponent from "components/designSystems/blueprint/DropdownComponent";
|
import DropDownComponent from "components/designSystems/blueprint/DropdownComponent";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
|
@ -111,6 +111,7 @@ class DropdownWidget extends BaseWidget<DropdownWidgetProps, WidgetState> {
|
||||||
)
|
)
|
||||||
.filter((i: number) => i > -1)
|
.filter((i: number) => i > -1)
|
||||||
: [];
|
: [];
|
||||||
|
const { componentWidth, componentHeight } = this.getComponentDimensions();
|
||||||
return (
|
return (
|
||||||
<DropDownComponent
|
<DropDownComponent
|
||||||
onOptionSelected={this.onOptionSelected}
|
onOptionSelected={this.onOptionSelected}
|
||||||
|
|
@ -118,6 +119,8 @@ class DropdownWidget extends BaseWidget<DropdownWidgetProps, WidgetState> {
|
||||||
widgetId={this.props.widgetId}
|
widgetId={this.props.widgetId}
|
||||||
placeholder={this.props.placeholderText}
|
placeholder={this.props.placeholderText}
|
||||||
options={options}
|
options={options}
|
||||||
|
height={componentHeight}
|
||||||
|
width={componentWidth}
|
||||||
selectionType={this.props.selectionType}
|
selectionType={this.props.selectionType}
|
||||||
selectedIndex={selectedIndex > -1 ? selectedIndex : undefined}
|
selectedIndex={selectedIndex > -1 ? selectedIndex : undefined}
|
||||||
selectedIndexArr={computedSelectedIndexArr}
|
selectedIndexArr={computedSelectedIndexArr}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user