Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 18 additions & 2 deletions src/Mentions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,24 @@ const InternalMentions = forwardRef<MentionsRef, InternalMentionsProps>(
onPopupScroll?.(event);
};

// ============================== Styles ==============================
const mergedStyles = React.useMemo(() => {
const resizeStyle = styles?.textarea?.resize ?? style?.resize;
const mergedTextareaStyle = { ...styles?.textarea };

// Only add resize if it has a valid value, avoid setting undefined
if (resizeStyle !== undefined) {
mergedTextareaStyle.resize = resizeStyle;
}

return {
...styles,
textarea: mergedTextareaStyle,
};
}, [style, styles]);

// ============================== Render ==============================

const mentionNode = (
<>
<TextArea
Expand All @@ -487,8 +504,7 @@ const InternalMentions = forwardRef<MentionsRef, InternalMentionsProps>(
* The TextArea component code and found that the resize parameter in the style of the ResizeTextArea component is obtained from prop.style.
* Just pass the resize attribute and leave everything else unchanged.
*/
style={{ resize: style?.resize }}
styles={{ textarea: styles?.textarea }}
styles={mergedStyles}
ref={textareaRef}
value={mergedValue}
{...restProps}
Expand Down
5 changes: 2 additions & 3 deletions tests/DropdownMenu.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';
import { render, fireEvent, act } from '@testing-library/react';
import KeyCode from '@rc-component/util/lib/KeyCode';
import { render, act } from '@testing-library/react';
import Mentions, { UnstableContext } from '../src';
import { expectMeasuring, simulateInput } from './util';
import { simulateInput } from './util';

describe('DropdownMenu', () => {
// Generate 20 options for testing scrolling behavior
Expand Down
18 changes: 18 additions & 0 deletions tests/Mentions.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,22 @@ describe('Mentions', () => {
// As all input options items have different values, so there's no case that a Mentions instance has duplicated menu item keys.
expect(uniqueMenuItemKeys.length).toBe(menuItemKeys.length);
});

describe('resize style', () => {
it('should apply resize style from style prop', () => {
const { container } = renderMentions({
style: { resize: 'vertical' },
});
const textarea = container.querySelector('textarea');
expect(textarea).toHaveStyle({ resize: 'vertical' });
});

it('should apply resize style from styles.textarea prop', () => {
const { container } = renderMentions({
styles: { textarea: { resize: 'vertical' } },
});
const textarea = container.querySelector('textarea');
expect(textarea).toHaveStyle({ resize: 'vertical' });
});
});
});