Merge pull request #5829 from Budibase/feature/clickable-container

Containers support onClick
This commit is contained in:
melohagan 2022-08-17 16:34:41 +01:00 committed by GitHub
commit b2ae542869
4 changed files with 28 additions and 5 deletions

View File

@ -36,7 +36,12 @@
}
}
const canRenderControl = setting => {
const canRenderControl = (setting, isScreen) => {
// Prevent rendering on click setting for screens
if (setting?.type === "event" && isScreen) {
return false
}
const control = getComponentForSetting(setting)
if (!control) {
return false
@ -87,7 +92,7 @@
/>
{/if}
{#each section.settings as setting (setting.key)}
{#if canRenderControl(setting)}
{#if canRenderControl(setting, isScreen)}
<PropertyControl
type={setting.type}
control={getComponentForSetting(setting)}

View File

@ -237,6 +237,11 @@
"showInBar": true,
"barIcon": "ModernGridView",
"barTitle": "Wrap"
},
{
"type": "event",
"label": "On Click",
"key": "onClick"
}
]
},

View File

@ -10,6 +10,7 @@
export let size
export let gap
export let wrap
export let onClick
$: directionClass = direction ? `valid-container direction-${direction}` : ""
$: hAlignClass = hAlign ? `hAlign-${hAlign}` : ""
@ -25,7 +26,13 @@
].join(" ")
</script>
<div class={classNames} use:styleable={$component.styles} class:wrap>
<div
class={classNames}
class:clickable={!!onClick}
use:styleable={$component.styles}
class:wrap
on:click={onClick}
>
<slot />
</div>
@ -104,4 +111,10 @@
.wrap {
flex-wrap: wrap;
}
.clickable {
cursor: pointer;
}
.clickable :global(*) {
pointer-events: none;
}
</style>

View File

@ -334,8 +334,8 @@ const confirmTextMap = {
*/
export const enrichButtonActions = (actions, context) => {
// Prevent button actions in the builder preview
if (!actions || get(builderStore).inBuilder) {
return () => {}
if (!actions?.length || get(builderStore).inBuilder) {
return null
}
// If this is a function then it has already been enriched