Skip to content

Commit 1e59c6b

Browse files
authored
fix: Select value truncation in attribute editor (#4135)
1 parent 1a05a16 commit 1e59c6b

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import React from 'react';
4+
5+
import { Box, Input, Select } from '~components';
6+
import AttributeEditor from '~components/attribute-editor';
7+
8+
import ScreenshotArea from '../utils/screenshot-area';
9+
10+
const longOptions = [
11+
{ label: 'Thisisaverylonglonglonglonglonglonglonglonglonglonglonglonglonglabel', value: '0' },
12+
{
13+
label: 'This is a very longlonglonglong longlonglonglonglong longlonglonglonglabel with spaces',
14+
value: '1',
15+
},
16+
];
17+
18+
const shortOptions = [
19+
{ label: 'Short', value: '0' },
20+
{
21+
label: 'Short value 1',
22+
value: '1',
23+
},
24+
];
25+
26+
export default function AttributeEditorSelect() {
27+
const [items, setItems] = React.useState([
28+
{
29+
key: 'some-key-1',
30+
value: 'some-value-1',
31+
longSelect: longOptions[0],
32+
shortSelect: shortOptions[0],
33+
},
34+
{
35+
key: 'some-key-2',
36+
value: 'some-value-2',
37+
longSelect: longOptions[1],
38+
shortSelect: shortOptions[1],
39+
},
40+
]);
41+
42+
return (
43+
<Box margin="xl">
44+
<h1>Attribute Editor - Long select</h1>
45+
<ScreenshotArea>
46+
<AttributeEditor
47+
items={items}
48+
hideAddButton={true}
49+
onRemoveButtonClick={({ detail: { itemIndex } }) => {
50+
const tmpItems = [...items];
51+
tmpItems.splice(itemIndex, 1);
52+
setItems(tmpItems);
53+
}}
54+
addButtonText="Add new item"
55+
removeButtonText="Remove"
56+
definition={[
57+
{
58+
label: 'Key',
59+
control: item => <Input value={item.key} placeholder="Enter key" onChange={() => {}} />,
60+
},
61+
{
62+
label: 'Long select',
63+
control: item => <Select selectedOption={item.longSelect} options={longOptions} />,
64+
},
65+
{
66+
label: 'Short select',
67+
control: item => <Select selectedOption={item.shortSelect} options={shortOptions} />,
68+
},
69+
]}
70+
/>
71+
</ScreenshotArea>
72+
</Box>
73+
);
74+
}

src/attribute-editor/styles.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
}
3636

3737
.field {
38-
/* used in test-utils */
38+
// needed for select truncation and to prevent fields from clashing
39+
min-inline-size: 40px;
3940
}
4041

4142
.additional-info {

0 commit comments

Comments
 (0)