Skip to content

Commit a5bf2af

Browse files
authored
fix(editor): fix styles in editor tab extra (#736)
* fix(editor): fix styles in editor tab extra * test(components): update tab test cases
1 parent 61b1753 commit a5bf2af

File tree

7 files changed

+58
-68
lines changed

7 files changed

+58
-68
lines changed

src/components/tabs/__tests__/__snapshots__/tabs.test.tsx.snap

+16-22
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,35 @@ exports[`The Tabs Components The snapshot 1`] = `
1313
onContextMenu={[Function]}
1414
>
1515
test-title-1
16-
<a
17-
className="mo-tab__item__op"
16+
<div
17+
className="mo-tab__item__extra"
18+
onClick={[Function]}
1819
onMouseOut={[Function]}
1920
onMouseOver={[Function]}
21+
role="button"
2022
>
21-
<div
22-
className="mo-tab__item__op__button"
23-
onClick={[Function]}
24-
>
25-
<span
26-
className="codicon codicon-close"
27-
/>
28-
</div>
29-
</a>
23+
<span
24+
className="codicon codicon-close"
25+
/>
26+
</div>
3027
</div>
3128
<div
3229
className="mo-tab__item"
3330
onClick={[Function]}
3431
onContextMenu={[Function]}
3532
>
3633
test-title-2
37-
<a
38-
className="mo-tab__item__op"
34+
<div
35+
className="mo-tab__item__extra"
36+
onClick={[Function]}
3937
onMouseOut={[Function]}
4038
onMouseOver={[Function]}
39+
role="button"
4140
>
42-
<div
43-
className="mo-tab__item__op__button"
44-
onClick={[Function]}
45-
>
46-
<span
47-
className="codicon codicon-close"
48-
/>
49-
</div>
50-
</a>
41+
<span
42+
className="codicon codicon-close"
43+
/>
44+
</div>
5145
</div>
5246
</div>
5347
</div>

src/components/tabs/__tests__/tabExtra.test.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ describe('The Tab Component', () => {
1717
test('Should render with classNames', () => {
1818
const { container } = render(<TabExtra classNames="test" />);
1919
const wrapper = container.querySelector('.test');
20-
const innerWrapper = wrapper?.querySelector('.test__button');
21-
expect(innerWrapper).toBeInTheDocument();
20+
expect(wrapper).toBeInTheDocument();
2221
});
2322

2423
test('Should support to the click event', () => {
@@ -27,10 +26,9 @@ describe('The Tab Component', () => {
2726
<TabExtra classNames="test" onClick={fn} />
2827
);
2928
const wrapper = container.querySelector('.test');
30-
const innerWrapper = wrapper?.querySelector('.test__button');
31-
expect(innerWrapper).not.toBeUndefined();
29+
expect(wrapper).not.toBeUndefined();
3230

33-
fireEvent.click(innerWrapper!);
31+
fireEvent.click(wrapper!);
3432
});
3533
});
3634

src/components/tabs/__tests__/tabs.test.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import { cleanup, fireEvent, render, waitFor } from '@testing-library/react';
33
import renderer from 'react-test-renderer';
44
import '@testing-library/jest-dom';
55
import { Tabs, tabsClassName } from '..';
6-
import { ITabProps, tabItemActiveClassName, tabItemClassName } from '../tab';
6+
import {
7+
ITabProps,
8+
tabItemActiveClassName,
9+
tabItemClassName,
10+
tabItemExtraClassName,
11+
} from '../tab';
712
import { dragToTargetNode } from '@test/utils';
813

914
const mockData: ITabProps[] = [
@@ -98,7 +103,9 @@ describe('The Tabs Components', () => {
98103
fireEvent.contextMenu(testHeader);
99104
expect(mockContextFn).toBeCalled();
100105

101-
fireEvent.mouseOver(testHeader.querySelector('.mo-tab__item__op')!);
106+
fireEvent.mouseOver(
107+
testHeader.querySelector(`.${tabItemExtraClassName}`)!
108+
);
102109
await waitFor(() => {
103110
fireEvent.click(testHeader.querySelector('.codicon-close')!);
104111
});

src/components/tabs/style.scss

+9-26
Original file line numberDiff line numberDiff line change
@@ -58,41 +58,24 @@
5858
}
5959
}
6060

61-
&:hover {
62-
#{$tab}__item__op {
63-
opacity: 1;
64-
}
65-
}
66-
67-
&__status,
68-
&__op {
61+
&__extra {
6962
font-size: 0;
70-
}
71-
72-
&__op {
73-
color: var(--icon-foreground);
74-
margin-left: 10px;
75-
opacity: 0;
76-
transform: translateY(1px);
77-
width: 20px;
63+
padding: 0 4px;
7864

79-
&__close {
80-
cursor: pointer;
81-
display: block;
82-
font-weight: 500;
83-
height: 18px;
84-
width: 18px;
65+
.codicon-close {
66+
opacity: 0;
8567
}
8668
}
8769

70+
&:hover .codicon-close,
71+
&--active .codicon-close {
72+
opacity: 1;
73+
}
74+
8875
&--active {
8976
background: var(--tab-activeBackground);
9077
border-bottom-color: var(--tab-activeBorder);
9178
color: var(--tab-activeForeground);
92-
93-
#{$tab}__item__op {
94-
opacity: 1;
95-
}
9679
}
9780

9881
&--close {

src/components/tabs/tab.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const tabItemActiveClassName = getBEMModifier(
6060
'active'
6161
);
6262
export const tabItemLabelClassName = getBEMElement(tabItemClassName, 'label');
63+
export const tabItemExtraClassName = getBEMElement(tabItemClassName, 'extra');
6364

6465
/**
6566
* The type definition for The Tab Component
@@ -152,10 +153,7 @@ export function Tab({ tab, active, ...restEvents }: ITabComponent) {
152153
{name}
153154
{(typeof closable === 'undefined' || closable) && (
154155
<TabExtra
155-
classNames={getBEMElement(
156-
tabItemClassName,
157-
status ? 'status' : 'op'
158-
)}
156+
classNames={tabItemExtraClassName}
159157
onClick={(e) => {
160158
e.stopPropagation();
161159
onCloseTab?.(id);

src/components/tabs/tabExtra.tsx

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useState } from 'react';
2-
import { getBEMElement } from 'mo/common/className';
32

43
interface ITabExtraProps {
54
classNames?: string;
@@ -19,17 +18,14 @@ export default ({ onClick, classNames = '', renderStatus }: ITabExtraProps) => {
1918
};
2019

2120
return (
22-
<a
21+
<div
22+
role="button"
2323
className={classNames}
24+
onClick={onClick}
2425
onMouseOver={handleMouseOver}
2526
onMouseOut={handleMouseOut}
2627
>
27-
<div
28-
className={getBEMElement(classNames, 'button')}
29-
onClick={onClick}
30-
>
31-
{renderStatus?.(hover)}
32-
</div>
33-
</a>
28+
{renderStatus?.(hover)}
29+
</div>
3430
);
3531
};

stories/extensions/test/testPane.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ export type GenericClassDecorator<T> = (target: T) => void;`,
209209
molecule.editor.open(tabData);
210210
};
211211

212+
const toggleEditorStatus = () => {
213+
const { current } = molecule.editor.getState();
214+
if (current?.tab) {
215+
molecule.editor.updateTab({
216+
id: current.tab.id,
217+
status:
218+
current.tab.status === 'edited' ? undefined : 'edited',
219+
});
220+
}
221+
};
222+
212223
const updateEntryPage = () => {
213224
const style: React.CSSProperties = {
214225
display: 'flex',
@@ -412,6 +423,9 @@ PARTITIONED BY (DE STRING) LIFECYCLE 1000;
412423
<div style={{ marginBottom: 50 }}>
413424
<h2>Simple examples:</h2>
414425
<Button onClick={newEditor}>New Editor</Button>
426+
<Button onClick={toggleEditorStatus}>
427+
Toggle Editor status
428+
</Button>
415429
<Button onClick={updateEntryPage}>
416430
Update Entry Page
417431
</Button>

0 commit comments

Comments
 (0)