Skip to content

Commit c3f83f9

Browse files
authored
[MM-67456] Allow OptionItem labels to wrap to two lines (#9504)
1 parent 1757654 commit c3f83f9

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
2+
// See LICENSE.txt for license information.
3+
4+
import React from 'react';
5+
6+
import OptionItem from '@components/option_item';
7+
import {renderWithIntlAndTheme} from '@test/intl-test-helper';
8+
9+
import BaseOption from './index';
10+
11+
jest.mock('@components/option_item');
12+
jest.mocked(OptionItem).mockImplementation((props) => React.createElement('OptionItem', props));
13+
14+
describe('BaseOption', () => {
15+
it('should force single line labels', () => {
16+
renderWithIntlAndTheme(
17+
<BaseOption
18+
message={{id: 'test.base_option.label', defaultMessage: 'Option label'}}
19+
iconName='icon-name'
20+
onPress={jest.fn()}
21+
testID='base-option'
22+
/>,
23+
);
24+
25+
expect(jest.mocked(OptionItem)).toHaveBeenCalled();
26+
expect(jest.mocked(OptionItem).mock.calls[0][0]).toEqual(expect.objectContaining({
27+
label: 'Option label',
28+
labelNumberOfLines: 1,
29+
type: 'default',
30+
testID: 'base-option',
31+
}));
32+
});
33+
});

app/components/common_post_options/base_option/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const BaseOption = ({
2929
destructive={isDestructive}
3030
icon={iconName}
3131
label={intl.formatMessage(message)}
32+
labelNumberOfLines={1}
3233
testID={testID}
3334
type='default'
3435
/>

app/components/option_item/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export type OptionItemProps = {
132132
value?: string;
133133
onLayout?: (event: LayoutChangeEvent) => void;
134134
descriptionNumberOfLines?: number;
135+
labelNumberOfLines?: number;
135136
longInfo?: boolean;
136137
nonDestructiveDescription?: boolean;
137138
isRadioCheckmark?: boolean;
@@ -155,6 +156,7 @@ const OptionItem = ({
155156
value,
156157
onLayout,
157158
descriptionNumberOfLines,
159+
labelNumberOfLines = 2,
158160
longInfo,
159161
nonDestructiveDescription = false,
160162
isRadioCheckmark = false,
@@ -326,7 +328,7 @@ const OptionItem = ({
326328
<Text
327329
style={labelTextStyle}
328330
testID={`${testID}.label`}
329-
numberOfLines={1}
331+
numberOfLines={labelNumberOfLines}
330332
>
331333
{label}
332334
</Text>

app/components/option_item/option_item.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe('OptionItem', () => {
4040
const label = getByText('Test Option');
4141
expect(label).toBeTruthy();
4242
expect(label).toHaveStyle({fontWeight: '400'});
43+
expect(label.props.numberOfLines).toBe(2);
4344

4445
// No description
4546
expect(queryByTestId('option-item.description')).toBeNull();
@@ -65,6 +66,16 @@ describe('OptionItem', () => {
6566
expect(queryByTestId('option-item.arrow.icon')).toBeNull();
6667
});
6768

69+
it('respects custom label number of lines', () => {
70+
const props = getBaseProps();
71+
props.labelNumberOfLines = 1;
72+
73+
const {getByText} = renderWithIntlAndTheme(<OptionItem {...props}/>);
74+
75+
const label = getByText('Test Option');
76+
expect(label.props.numberOfLines).toBe(1);
77+
});
78+
6879
it('renders with description when provided', () => {
6980
const props = getBaseProps();
7081
props.description = 'Test description';

app/screens/post_options/options/app_bindings_post_option.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const BindingOptionItem = ({binding, onPress}: {binding: AppBinding; onPress: (b
7777
return (
7878
<OptionItem
7979
label={binding.label || ''}
80+
labelNumberOfLines={1}
8081
icon={binding.icon}
8182
action={handlePress}
8283
type='default'

0 commit comments

Comments
 (0)