Skip to content

Commit d4424b2

Browse files
eos87petrjasek
authored andcommitted
Revert "Fix authoring react vocabulary field moving on a different row if sel…" (#5108)
This reverts commit b11823c.
1 parent a5dfafe commit d4424b2

File tree

3 files changed

+31
-298
lines changed

3 files changed

+31
-298
lines changed

scripts/apps/authoring-react/fields/README.md

Lines changed: 0 additions & 190 deletions
This file was deleted.

scripts/apps/authoring-react/fields/dropdown/dropdown-item-template.tsx

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -13,80 +13,9 @@ interface IProps {
1313
noPadding: boolean;
1414
}
1515

16-
interface IState {
17-
availableWidth: number | null;
18-
}
19-
20-
/**
21-
* This component should only be used within a `MultiSelectTreeWithTemplate` component
22-
*/
23-
export class DropdownItemTemplate extends React.PureComponent<IProps, IState> {
24-
private containerRef: React.RefObject<HTMLSpanElement>;
25-
26-
constructor(props: IProps) {
27-
super(props);
28-
this.containerRef = React.createRef();
29-
this.state = {
30-
availableWidth: null,
31-
};
32-
}
33-
34-
componentDidMount() {
35-
this.calculateAvailableWidth();
36-
}
37-
38-
componentDidUpdate() {
39-
this.calculateAvailableWidth();
40-
}
41-
42-
private calculateAvailableWidth = () => {
43-
const container = this.containerRef.current;
44-
45-
if (container == null) {
46-
return;
47-
}
48-
49-
// Find the tags-input__helper-box or tags-input__single-item container
50-
let widthContainer: HTMLElement | null = container.parentElement;
51-
52-
while (widthContainer != null) {
53-
if (
54-
widthContainer.classList.contains('tags-input__helper-box') ||
55-
widthContainer.classList.contains('tags-input__single-item')
56-
) {
57-
break;
58-
}
59-
60-
widthContainer = widthContainer.parentElement;
61-
}
62-
63-
if (widthContainer == null) {
64-
return;
65-
}
66-
67-
const containerWidth = widthContainer.clientWidth;
68-
const containerStyle = window.getComputedStyle(widthContainer);
69-
const containerPadding = parseFloat(containerStyle.paddingLeft) + parseFloat(containerStyle.paddingRight);
70-
71-
// Account for sibling elements (like the remove button)
72-
let siblingsWidth = 0;
73-
74-
for (const child of Array.from(widthContainer.children)) {
75-
if (!child.contains(container)) {
76-
siblingsWidth += (child as HTMLElement).offsetWidth;
77-
}
78-
}
79-
80-
const availableWidth = containerWidth - containerPadding - siblingsWidth;
81-
82-
if (availableWidth !== this.state.availableWidth && availableWidth > 0) {
83-
this.setState({availableWidth});
84-
}
85-
};
86-
16+
export class DropdownItemTemplate extends React.PureComponent<IProps> {
8717
render() {
8818
const {option, noPadding, config} = this.props;
89-
const {availableWidth} = this.state;
9019

9120
if (option == null) {
9221
return null;
@@ -95,26 +24,18 @@ export class DropdownItemTemplate extends React.PureComponent<IProps, IState> {
9524
const itemStyle: React.CSSProperties = {
9625
height: '1.5em',
9726
minWidth: '1.5em',
98-
maxWidth: availableWidth != null ? `${availableWidth}px` : undefined,
9927
backgroundColor: option.color ?? 'transparent',
10028
color: option.color == null ? 'black' : getTextColor(option.color),
10129
display: 'inline-flex',
10230
justifyContent: 'center',
10331
alignItems: 'center',
10432
borderRadius: config.source === 'manual-entry' && config.roundCorners ? '999px' : '2px',
10533
padding: noPadding ? '0' : '4px',
106-
};
107-
108-
const labelStyle: React.CSSProperties = {
10934
whiteSpace: 'nowrap',
110-
overflow: 'hidden',
111-
textOverflow: 'ellipsis',
11235
};
11336

11437
return (
115-
<span ref={this.containerRef} style={itemStyle}>
116-
<span style={labelStyle}>{option.label}</span>
117-
</span>
38+
<span style={itemStyle}>{option.label}</span>
11839
);
11940
}
12041
}

scripts/apps/authoring-react/fields/dropdown/editor-using-manual-source-or-vocabulary.tsx

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,37 @@ export class EditorUsingManualSourceOrVocabulary extends React.PureComponent<IPr
3030
render() {
3131
const {config} = this.props;
3232
const Container = this.props.container;
33-
let values: Array<string> | Array<number>;
33+
const values: Array<string> | Array<number> = (() => {
34+
if (this.props.value == null) {
35+
return [];
36+
} else if (Array.isArray(this.props.value)) {
37+
return this.props.value;
38+
} else {
39+
return [this.props.value];
40+
}
41+
})();
3442

35-
if (this.props.value == null) {
36-
values = [];
37-
} else if (Array.isArray(this.props.value)) {
38-
values = this.props.value;
39-
} else {
40-
values = [this.props.value] as Array<string> | Array<number>;
41-
}
42-
43-
let options: ITreeWithLookup<IDropdownOption>;
43+
const options: ITreeWithLookup<IDropdownOption> = (() => {
44+
if (config.source === 'manual-entry') {
45+
const _options: ITreeWithLookup<IDropdownOption> = {
46+
nodes: arrayToTree(
47+
config.options,
48+
({id}) => id.toString(),
49+
({parent}) => parent?.toString(),
50+
).result,
51+
lookup: keyBy(
52+
config.options.map((opt) => ({value: opt})),
53+
(opt) => opt.value.id.toString(),
54+
),
55+
};
4456

45-
if (config.source === 'manual-entry') {
46-
options = {
47-
nodes: arrayToTree(
48-
config.options,
49-
({id}) => id.toString(),
50-
({parent}) => parent?.toString(),
51-
).result,
52-
lookup: keyBy(
53-
config.options.map((opt) => ({value: opt})),
54-
(opt) => opt.value.id.toString(),
55-
),
56-
};
57-
} else if (config.source === 'vocabulary') {
58-
options = getOptions(config, this.props.getVocabularyItems);
59-
} else {
60-
assertNever(config);
61-
}
57+
return _options;
58+
} else if (config.source === 'vocabulary') {
59+
return getOptions(config, this.props.getVocabularyItems);
60+
} else {
61+
assertNever(config);
62+
}
63+
})();
6264

6365
const selected =
6466
values

0 commit comments

Comments
 (0)