Skip to content

Commit

Permalink
Merge pull request #1762 from simon-leech/tabview-btnRow
Browse files Browse the repository at this point in the history
Tabview BtnRow must be set to display block in the `activate`
  • Loading branch information
RobAndrewHurst authored Nov 27, 2024
2 parents acf6f18 + 31bce2c commit 657652a
Showing 1 changed file with 44 additions and 33 deletions.
77 changes: 44 additions & 33 deletions lib/ui/Tabview.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,49 +78,24 @@ function addTab(entry) {

const tabview = this

entry.activate ??= function(){

if (entry.create === undefined) {

entry.create ??= function () {
mapp.ui.utils[entry.dataview]?.create(entry);
}

entry.create()

} else if (entry.dynamic) {

entry.create()
}

if (entry.update instanceof Function) {

if (!entry.data || entry.activateUpdate) {

// Call dataview update method if data is falsy or activateUpdate flag is set.
entry.update()
}
}
}
entry.activate ??= activateTab

if (entry.location) {

// The tabview should be removed if the location is removed.
entry.location.removeCallbacks.push(()=>entry.remove())
entry.location.removeCallbacks.push(() => entry.remove())

}

else if (entry.layer) {
} else if (entry.layer) {

// Show tab when layer is displayed.
entry.layer.showCallbacks.push(()=>{
entry.layer.showCallbacks.push(() => {

// Entry must have display flag.
entry.display && entry.show()
})

// Hide tab when layer is hidden.
entry.layer.hideCallbacks.push(()=>{
entry.layer.hideCallbacks.push(() => {
entry.remove()
})
}
Expand All @@ -134,7 +109,7 @@ function addTab(entry) {
class="header"
style="${entry.tab_style || ''}"
onclick=${showTab}>${entry.label}`

entry.panel ??= entry.target || mapp.utils.html.node`
<div class="${`panel ${entry.class || ''}`}">`

Expand All @@ -145,6 +120,42 @@ function addTab(entry) {
// Must override dataview hide method.
entry.hide = removeTab

/**
@function activateTab
@description
The activateTab method is debounced for tabs being shown/added to a tabview. A tab may be a dataview object which requires to be created/updated within the context of the tab.
The dataview may have an associated toolbar [btnRow element] which must be displayed.
*/
function activateTab() {

if (entry.create === undefined) {

entry.create ??= function () {
mapp.ui.utils[entry.dataview]?.create(entry);
}

entry.create()

} else if (entry.dynamic) {

entry.create()
}

if (entry.update instanceof Function) {

if (!entry.data || entry.activateUpdate) {

// Call dataview update method if data is falsy or activateUpdate flag is set.
entry.update()
}
}

//Show toolbar buttons if there are any
entry.btnRow?.style.setProperty('display', 'block')
}

/**
@function showTab
Expand Down

0 comments on commit 657652a

Please sign in to comment.