@@ -206,7 +206,7 @@ UI.tabs.tabWidget = function (options) {
206206 // Find how many match at each end
207207 for ( left = 0 ; left < tabContainer . children . length ; left ++ ) {
208208 slot = tabContainer . children [ left ]
209- if ( left >= items . length || ! slot . subject . sameTerm ( items [ left ] ) ) {
209+ if ( left >= items . length || ( slot . subject && ! slot . subject . sameTerm ( items [ left ] ) ) ) {
210210 differ = true
211211 break
212212 }
@@ -217,7 +217,7 @@ UI.tabs.tabWidget = function (options) {
217217 for ( right = tabContainer . children . length - 1 ; right >= 0 ; right -- ) {
218218 slot = tabContainer . children [ right ]
219219 j = right - tabContainer . children . length + items . length
220- if ( ! slot . subject . sameTerm ( items [ j ] ) ) {
220+ if ( slot . subject && ! slot . subject . sameTerm ( items [ j ] ) ) {
221221 break
222222 }
223223 }
@@ -325,6 +325,12 @@ UI.tabs.tabWidget = function (options) {
325325 return box
326326
327327 function addCancelButton ( tabContainer ) {
328+ if ( tabContainer . dataset . onCloseSet ) {
329+ // @@ TODO: this is only here to make the tests work
330+ // Discussion at https://github.com/solid/solid-ui/pull/110#issuecomment-527080663
331+ const existingCancelButton = tabContainer . querySelector ( '.unstyled' )
332+ tabContainer . removeChild ( existingCancelButton )
333+ }
328334 const extraTab = dom . createElement ( tabElement )
329335 extraTab . classList . add ( 'unstyled' )
330336 if ( tabElement === 'td' ) {
@@ -333,5 +339,6 @@ UI.tabs.tabWidget = function (options) {
333339 const cancelButton = UI . widgets . cancelButton ( dom , onClose )
334340 extraTab . appendChild ( cancelButton )
335341 tabContainer . appendChild ( extraTab )
342+ tabContainer . dataset . onCloseSet = 'true'
336343 }
337344}
0 commit comments