@@ -88,6 +88,22 @@ import React, { Fragment, useState, useCallback } from 'react';
8888import Tabs , { Tab , useDataContext } from ' @uiw/react-tabs-draggable' ;
8989import styled from ' styled-components' ;
9090
91+ const TabWarp = styled (Tabs)`
92+ max-width: 450px;
93+ border-bottom: 1px solid #333;
94+ margin-bottom: -2px;
95+ &:hover::-webkit-scrollbar {
96+ height: 0px;
97+ background-color: red;
98+ }
99+ &:hover::-webkit-scrollbar-track {
100+ background-color: #333;
101+ }
102+ &:hover::-webkit-scrollbar-thumb {
103+ background-color: green;
104+ }
105+ ` ;
106+
91107const TabItem = styled (Tab)`
92108 background-color: #b9b9b9;
93109 padding: 3px 7px;
@@ -99,25 +115,25 @@ const TabItem = styled(Tab)`
99115 }
100116` ;
101117
102- const Content = styled .div `
103- border-top: 1px solid #333;
104- ` ;
105-
106118function insertAndShift (arr , from , to ) {
107119 let cutOut = arr .splice (from, 1 )[0 ];
108120 arr .splice (to, 0 , cutOut);
109121 return arr;
110122}
111123
112- let count = 5 ;
124+ let count = 9 ;
113125
114126function App () {
115127 const [data , setData ] = useState ([
116- { id: ' tab-3-1' , children: ' Google' },
117- { id: ' tab-3-2' , children: ' MicroSoft' },
118- { id: ' tab-3-3' , children: ' Baidu' },
119- { id: ' tab-3-4' , children: ' Taobao' },
120- { id: ' tab-3-5' , children: ' JD' },
128+ { id: ' tab-4-1' , children: ' Google' },
129+ { id: ' tab-4-2' , children: ' MicroSoft' },
130+ { id: ' tab-4-3' , children: ' Baidu' },
131+ { id: ' tab-4-4' , children: ' Taobao' },
132+ { id: ' tab-4-5' , children: ' JD' },
133+ { id: ' tab-4-6' , children: ' Apple' },
134+ { id: ' tab-4-7' , children: ' Bing' },
135+ { id: ' tab-4-8' , children: ' Gmail' },
136+ { id: ' tab-4-9' , children: ' Gitter' },
121137 ]);
122138 const [test , setTest ] = useState (1 );
123139 const [activeKey , setActiveKey ] = useState (' ' );
@@ -143,8 +159,8 @@ function App() {
143159 };
144160 return (
145161 < Fragment>
146- < button onClick= {addHandle}> Add{test }< / button>
147- < Tabs
162+ < button onClick= {addHandle}> Add{count }< / button>
163+ < TabWarp
148164 style= {{ gap: 3 , overflow: ' auto' }}
149165 onTabClick= {(id , evn ) => tabClick (id, evn)}
150166 onTabDrop= {(id , index ) => tabDrop (id, index)}
@@ -157,8 +173,8 @@ function App() {
157173 < / TabItem>
158174 );
159175 })}
160- < / Tabs >
161- < Content > {activeKey}< / Content >
176+ < / TabWarp >
177+ < div > {activeKey}< / div >
162178 < / Fragment>
163179 );
164180}
@@ -170,40 +186,50 @@ import React, { Fragment, useState, useCallback } from 'react';
170186import Tabs , { Tab , useDataContext } from ' @uiw/react-tabs-draggable' ;
171187import styled from ' styled-components' ;
172188
189+ const TabWarp = styled (Tabs)`
190+ max-width: 450px;
191+ border-bottom: 1px solid #333;
192+ margin-bottom: -2px;
193+ gap: 3px;
194+ ` ;
195+
173196const TabItem = styled (Tab)`
174197 background-color: #b9b9b9;
175198 padding: 3px 7px;
176199 border-radius: 5px 5px 0 0;
177200 user-select: none;
201+ flex-wrap: nowrap;
202+ overflow: hidden;
203+ word-break: keep-all;
204+ align-items: center;
205+ display: flex;
206+ position: relative;
207+ flex-direction: row;
178208 &.w-active {
179209 color: #fff;
180210 background-color: #333;
181211 }
182212` ;
183213
184- const Content = styled .div `
185- border-top: 1px solid #333;
186- ` ;
187-
188214function insertAndShift (arr , from , to ) {
189215 let cutOut = arr .splice (from, 1 )[0 ];
190216 arr .splice (to, 0 , cutOut);
191217 return arr;
192218}
193219
194- let count = 5 ;
220+ let count = 9 ;
195221
196222function App () {
197223 const [data , setData ] = useState ([
198- { id: ' tab-3 -1' , children: ' Google' },
199- { id: ' tab-3 -2' , children: ' MicroSoft' },
200- { id: ' tab-3 -3' , children: ' Baidu' },
201- { id: ' tab-3 -4' , children: ' Taobao' },
202- { id: ' tab-3 -5' , children: ' JD' },
203- { id: ' tab-3 -6' , children: ' Apple' },
204- { id: ' tab-3 -7' , children: ' Bing' },
205- { id: ' tab-3 -8' , children: ' Gmail' },
206- { id: ' tab-3 -9' , children: ' Gitter' },
224+ { id: ' tab-4 -1' , children: ' Google' },
225+ { id: ' tab-4 -2' , children: ' MicroSoft' },
226+ { id: ' tab-4 -3' , children: ' Baidu' },
227+ { id: ' tab-4 -4' , children: ' Taobao' },
228+ { id: ' tab-4 -5' , children: ' JD' },
229+ { id: ' tab-4 -6' , children: ' Apple' },
230+ { id: ' tab-4 -7' , children: ' Bing' },
231+ { id: ' tab-4 -8' , children: ' Gmail' },
232+ { id: ' tab-4 -9' , children: ' Gitter' },
207233 ]);
208234 const [test , setTest ] = useState (1 );
209235 const [activeKey , setActiveKey ] = useState (' ' );
@@ -229,22 +255,18 @@ function App() {
229255 };
230256 return (
231257 < Fragment>
232- < button onClick= {addHandle}> Add{test}< / button>
233- < Tabs
234- style= {{ gap: 3 , overflow: ' auto' }}
235- onTabClick= {(id , evn ) => tabClick (id, evn)}
236- onTabDrop= {(id , index ) => tabDrop (id, index)}
237- >
258+ < button onClick= {addHandle}> Add{count}< / button>
259+ < TabWarp style= {{}} onTabClick= {(id , evn ) => tabClick (id, evn)} onTabDrop= {(id , index ) => tabDrop (id, index)}>
238260 {data .map ((m , idx ) => {
239261 return (
240- < TabItem key= {idx} id= {m .id } draggable = {idx !== 0 } >
262+ < TabItem key= {idx} id= {m .id }>
241263 {m .children }
242264 < button onClick= {(evn ) => closeHandle (m, evn)}> x< / button>
243265 < / TabItem>
244266 );
245267 })}
246- < / Tabs >
247- < Content > {activeKey}< / Content >
268+ < / TabWarp >
269+ < div > {activeKey}< / div >
248270 < / Fragment>
249271 );
250272}
0 commit comments