Skip to content

Commit 17c9914

Browse files
authored
fix: resize style should work (#305)
* fix: resize style should work * chore: misc
1 parent ea9cf7d commit 17c9914

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

src/Mentions.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,24 @@ const InternalMentions = forwardRef<MentionsRef, InternalMentionsProps>(
476476
onPopupScroll?.(event);
477477
};
478478

479+
// ============================== Styles ==============================
480+
const mergedStyles = React.useMemo(() => {
481+
const resizeStyle = styles?.textarea?.resize ?? style?.resize;
482+
const mergedTextareaStyle = { ...styles?.textarea };
483+
484+
// Only add resize if it has a valid value, avoid setting undefined
485+
if (resizeStyle !== undefined) {
486+
mergedTextareaStyle.resize = resizeStyle;
487+
}
488+
489+
return {
490+
...styles,
491+
textarea: mergedTextareaStyle,
492+
};
493+
}, [style, styles]);
494+
479495
// ============================== Render ==============================
496+
480497
const mentionNode = (
481498
<>
482499
<TextArea
@@ -487,8 +504,7 @@ const InternalMentions = forwardRef<MentionsRef, InternalMentionsProps>(
487504
* The TextArea component code and found that the resize parameter in the style of the ResizeTextArea component is obtained from prop.style.
488505
* Just pass the resize attribute and leave everything else unchanged.
489506
*/
490-
style={{ resize: style?.resize }}
491-
styles={{ textarea: styles?.textarea }}
507+
styles={mergedStyles}
492508
ref={textareaRef}
493509
value={mergedValue}
494510
{...restProps}

tests/DropdownMenu.spec.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
2-
import { render, fireEvent, act } from '@testing-library/react';
3-
import KeyCode from '@rc-component/util/lib/KeyCode';
2+
import { render, act } from '@testing-library/react';
43
import Mentions, { UnstableContext } from '../src';
5-
import { expectMeasuring, simulateInput } from './util';
4+
import { simulateInput } from './util';
65

76
describe('DropdownMenu', () => {
87
// Generate 20 options for testing scrolling behavior

tests/Mentions.spec.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,4 +368,22 @@ describe('Mentions', () => {
368368
// As all input options items have different values, so there's no case that a Mentions instance has duplicated menu item keys.
369369
expect(uniqueMenuItemKeys.length).toBe(menuItemKeys.length);
370370
});
371+
372+
describe('resize style', () => {
373+
it('should apply resize style from style prop', () => {
374+
const { container } = renderMentions({
375+
style: { resize: 'vertical' },
376+
});
377+
const textarea = container.querySelector('textarea');
378+
expect(textarea).toHaveStyle({ resize: 'vertical' });
379+
});
380+
381+
it('should apply resize style from styles.textarea prop', () => {
382+
const { container } = renderMentions({
383+
styles: { textarea: { resize: 'vertical' } },
384+
});
385+
const textarea = container.querySelector('textarea');
386+
expect(textarea).toHaveStyle({ resize: 'vertical' });
387+
});
388+
});
371389
});

0 commit comments

Comments
 (0)