Skip to content

Commit 8d319fb

Browse files
committed
feat: arrow config support style
1 parent bac9320 commit 8d319fb

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

src/Popup/Arrow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ArrowProps {
1212
export default function Arrow(props: ArrowProps) {
1313
const { prefixCls, align, arrow, arrowPos } = props;
1414

15-
const { className, content } = arrow || {};
15+
const { className, content, style } = arrow || {};
1616
const { x = 0, y = 0 } = arrowPos;
1717

1818
const arrowRef = React.useRef<HTMLDivElement>(null);
@@ -58,7 +58,7 @@ export default function Arrow(props: ArrowProps) {
5858
<div
5959
ref={arrowRef}
6060
className={classNames(`${prefixCls}-arrow`, className)}
61-
style={alignStyle}
61+
style={{ ...alignStyle, ...style }}
6262
>
6363
{content}
6464
</div>

src/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export interface AlignType {
8989
}
9090

9191
export interface ArrowTypeOuter {
92+
style?: React.CSSProperties;
9293
className?: string;
9394
content?: React.ReactNode;
9495
}

tests/arrow.test.jsx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,66 @@ describe('Trigger.Arrow', () => {
188188
const arrowDom = document.querySelector('.rc-trigger-popup-arrow');
189189
expect(arrowDom.classList.contains('abc')).toBeTruthy();
190190
});
191+
192+
it('arrow style', async () => {
193+
render(
194+
<Trigger
195+
popupVisible
196+
popupAlign={{
197+
points: ['cl', 'cr'],
198+
autoArrow: false,
199+
}}
200+
popup={<strong>trigger</strong>}
201+
arrow={{
202+
style: {
203+
color: 'red',
204+
backgroundColor: 'blue',
205+
},
206+
}}
207+
>
208+
<div />
209+
</Trigger>,
210+
);
211+
212+
await awaitFakeTimer();
213+
214+
const arrowDom = document.querySelector('.rc-trigger-popup-arrow');
215+
expect(arrowDom).toHaveStyle({
216+
color: 'red',
217+
backgroundColor: 'blue',
218+
});
219+
});
220+
221+
it('arrow style should merge with align style', async () => {
222+
render(
223+
<Trigger
224+
popupVisible
225+
popupAlign={{
226+
points: ['cl', 'cr'],
227+
autoArrow: true,
228+
}}
229+
popup={<strong>trigger</strong>}
230+
arrow={{
231+
style: {
232+
color: 'red',
233+
backgroundColor: 'blue',
234+
},
235+
}}
236+
>
237+
<div />
238+
</Trigger>,
239+
);
240+
241+
await awaitFakeTimer();
242+
243+
const arrowDom = document.querySelector('.rc-trigger-popup-arrow');
244+
// Should have both align style (left: 0) and custom style
245+
expect(arrowDom).toHaveStyle({
246+
left: 0,
247+
color: 'red',
248+
backgroundColor: 'blue',
249+
});
250+
});
191251
});
192252

193253
it('content', async () => {

0 commit comments

Comments
 (0)