Expanding the focus behaviour to more component types in the builder. Minor fix for cypress test

This commit is contained in:
Dean 2022-05-24 09:58:05 +01:00
parent ecaae0ed8d
commit 702b62f8e6
16 changed files with 104 additions and 53 deletions

View File

@ -13,6 +13,10 @@
export let size = "M" export let size = "M"
export let active = false export let active = false
export let fullWidth = false export let fullWidth = false
export let autofocus = false
let focus = false
$: focus = autofocus
function longPress(element) { function longPress(element) {
if (!longPressable) return if (!longPressable) return
@ -44,9 +48,16 @@
class:fullWidth class:fullWidth
class="spectrum-ActionButton spectrum-ActionButton--size{size}" class="spectrum-ActionButton spectrum-ActionButton--size{size}"
class:active class:active
class:is-focused={focus}
{disabled} {disabled}
on:longPress on:longPress
on:click|preventDefault on:click|preventDefault
on:focus={() => {
focus = true
}}
on:blur={() => {
focus = false
}}
> >
{#if longPressable} {#if longPressable}
<svg <svg
@ -80,4 +91,10 @@
.active svg { .active svg {
color: var(--spectrum-global-color-blue-600); color: var(--spectrum-global-color-blue-600);
} }
button.is-focused {
border-color: var(
--spectrum-textfield-m-border-color-down,
var(--spectrum-alias-border-color-mouse-focus)
);
}
</style> </style>

View File

@ -56,8 +56,12 @@
bind:this={comboInput} bind:this={comboInput}
{id} {id}
type="text" type="text"
on:focus={() => (focus = true)} on:focus={() => {
on:blur={() => (focus = false)} focus = true
}}
on:blur={() => {
focus = false
}}
on:change={onType} on:change={onType}
value={value || ""} value={value || ""}
placeholder={placeholder || ""} placeholder={placeholder || ""}

View File

@ -118,20 +118,14 @@ filterTests(['all'], () => {
cy.get("[data-cy=setting-field] .spectrum-InputGroup") cy.get("[data-cy=setting-field] .spectrum-InputGroup")
.should("have.class", "is-focused").within(() => { .should("have.class", "is-focused").within(() => {
cy.get("input").should(($input) => { cy.get("input").should(($input) => {
expect($input).to.have.length(1)
inputClasses = Cypress.$($input).attr('class') inputClasses = Cypress.$($input).attr('class')
}) })
}) })
cy.focused().then(($focused) => {
const focusedClasses = Cypress.$($focused).attr('class')
expect(inputClasses).to.equal(focusedClasses)
})
} }
const testFieldFocusOnCreate = (componentLabel) => { const testFieldFocusOnCreate = (componentLabel) => {
let inputClasses let inputClasses
cy.log("Adding: " + componentLabel)
cy.addComponent("Form", componentLabel).then((componentId) => { cy.addComponent("Form", componentLabel).then((componentId) => {
refocusTest(componentId) refocusTest(componentId)
@ -139,15 +133,10 @@ filterTests(['all'], () => {
cy.get("[data-cy=setting-field] .spectrum-InputGroup") cy.get("[data-cy=setting-field] .spectrum-InputGroup")
.should("have.class", "is-focused").within(() => { .should("have.class", "is-focused").within(() => {
cy.get("input").should(($input) => { cy.get("input").should(($input) => {
expect($input).to.have.length(1)
inputClasses = Cypress.$($input).attr('class') inputClasses = Cypress.$($input).attr('class')
}) })
}) })
}) })
cy.focused().then(($focused) => {
const focusedClasses = Cypress.$($focused).attr('class')
expect(inputClasses).to.equal(focusedClasses)
})
} }
componentTypeLabels.forEach( testFieldFocusOnCreate ) componentTypeLabels.forEach( testFieldFocusOnCreate )

View File

@ -425,8 +425,10 @@ export const getFrontendStore = () => {
state.currentView = "component" state.currentView = "component"
state.selectedComponentId = componentInstance._id state.selectedComponentId = componentInstance._id
const focusSetting = definition.settings.filter((setting) => { return setting.required }) const focusSetting = definition.settings.filter(setting => {
const mappedSettings = focusSetting.map((setting) => { return setting.required
})
const mappedSettings = focusSetting.map(setting => {
return { return {
key: setting.key, key: setting.key,
target: state.selectedComponentId, target: state.selectedComponentId,
@ -434,7 +436,7 @@ export const getFrontendStore = () => {
} }
}) })
if(focusSetting.length){ if (focusSetting.length) {
state.builderFocus = mappedSettings state.builderFocus = mappedSettings
} }
return state return state

View File

@ -210,7 +210,7 @@
store.update(state => ({ store.update(state => ({
...state, ...state,
builderFocus : builderFocus :
[{...data}] [...data]
})) }))
} else { } else {
console.warn(`Client sent unknown event type: ${type}`) console.warn(`Client sent unknown event type: ${type}`)

View File

@ -15,6 +15,7 @@
export let value = "" export let value = ""
export let maxIconsPerPage = 30 export let maxIconsPerPage = 30
export let autofocus = false
let searchTerm = "" let searchTerm = ""
let selectedLetter = "A" let selectedLetter = "A"
@ -117,7 +118,9 @@
</script> </script>
<div bind:this={buttonAnchor}> <div bind:this={buttonAnchor}>
<ActionButton on:click={dropdown.show}>{displayValue}</ActionButton> <ActionButton on:click={dropdown.show} {autofocus}>
{displayValue}
</ActionButton>
</div> </div>
<Popover bind:this={dropdown} on:open={setSelectedUI} anchor={buttonAnchor}> <Popover bind:this={dropdown} on:open={setSelectedUI} anchor={buttonAnchor}>
<div class="container"> <div class="container">

View File

@ -4,6 +4,7 @@
export let value export let value
export let bindings export let bindings
export let autofocus
$: urlOptions = $store.screens $: urlOptions = $store.screens
.map(screen => screen.routing?.route) .map(screen => screen.routing?.route)
@ -16,4 +17,5 @@
on:change on:change
options={urlOptions} options={urlOptions}
appendBindingsAsOptions={false} appendBindingsAsOptions={false}
{autofocus}
/> />

View File

@ -201,7 +201,6 @@
class="components-pane" class="components-pane"
use:clickOutside={() => { use:clickOutside={() => {
if ($store?.builderFocus) { if ($store?.builderFocus) {
console.log($store?.builderFocus)
const otherSettings = $store?.builderFocus?.filter(field => { const otherSettings = $store?.builderFocus?.filter(field => {
return field.location !== "component_settings" return field.location !== "component_settings"
}) })

View File

@ -1034,7 +1034,8 @@
{ {
"type": "icon", "type": "icon",
"label": "Icon", "label": "Icon",
"key": "icon" "key": "icon",
"required": true
}, },
{ {
"type": "select", "type": "select",

View File

@ -34,11 +34,13 @@
<span <span
class="showMe spectrum-Link" class="showMe spectrum-Link"
on:click={() => { on:click={() => {
builderStore.actions.setFocus({ builderStore.actions.setFocus([
location: "component_settings", {
key: "url", location: "component_settings",
target: $component.id, key: "url",
}) target: $component.id,
},
])
}} }}
> >
Show me Show me

View File

@ -28,14 +28,29 @@
/> />
{:else if $builderStore.inBuilder} {:else if $builderStore.inBuilder}
<div use:styleable={styles}> <div use:styleable={styles}>
<Placeholder /> <Placeholder>
<div slot="content">
Add the <mark>Icon</mark> in the settings menu&nbsp;
<span
class="showMe spectrum-Link"
on:click={() => {
builderStore.actions.setFocus([
{
location: "component_settings",
key: "icon",
target: $component.id,
},
])
}}
>
Show me
</span>
</div>
</Placeholder>
</div> </div>
{/if} {/if}
<style> <style>
div {
font-style: italic;
}
@media (hover: hover) { @media (hover: hover) {
.hoverable:hover { .hoverable:hover {
color: var(--spectrum-alias-icon-color-selected-hover) !important; color: var(--spectrum-alias-icon-color-selected-hover) !important;

View File

@ -21,11 +21,13 @@
<span <span
class="showMe spectrum-Link" class="showMe spectrum-Link"
on:click={() => { on:click={() => {
builderStore.actions.setFocus({ builderStore.actions.setFocus([
location: "component_settings", {
key: "url", location: "component_settings",
target: $component.id, key: "url",
}) target: $component.id,
},
])
}} }}
> >
Show me Show me

View File

@ -21,11 +21,13 @@
<span <span
class="showMe spectrum-Link" class="showMe spectrum-Link"
on:click={() => { on:click={() => {
builderStore.actions.setFocus({ builderStore.actions.setFocus([
location: "component_settings", {
key: "value", location: "component_settings",
target: $component.id, key: "value",
}) target: $component.id,
},
])
}} }}
> >
Show me Show me

View File

@ -15,16 +15,27 @@
<div use:styleable={$component.styles}> <div use:styleable={$component.styles}>
<Placeholder> <Placeholder>
<div slot="content"> <div slot="content">
Use the settings panel to select a <mark>Provider</mark> and start Use the settings panel start building your chart&nbsp;
building your chart&nbsp;
<span <span
class="showMe spectrum-Link" class="showMe spectrum-Link"
on:click={() => { on:click={() => {
builderStore.actions.setFocus({ builderStore.actions.setFocus([
location: "component_settings", {
key: "dataProvider", location: "component_settings",
target: $component.id, key: "dataProvider",
}) target: $component.id,
},
{
location: "component_settings",
key: "valueColumns",
target: $component.id,
},
{
location: "component_settings",
key: "dataColumns",
target: $component.id,
},
])
}} }}
> >
Show me Show me

View File

@ -84,11 +84,13 @@
<span <span
class="showMe spectrum-Link" class="showMe spectrum-Link"
on:click={() => { on:click={() => {
builderStore.actions.setFocus({ builderStore.actions.setFocus([
location: "component_settings", {
key: "field", location: "component_settings",
target: $component.id, key: "field",
}) target: $component.id,
},
])
}} }}
> >
Show me Show me

View File

@ -78,7 +78,7 @@ const createBuilderStore = () => {
}, },
setFocus: data => { setFocus: data => {
window.parent.postMessage({ type: "builder-focus", data }) window.parent.postMessage({ type: "builder-focus", data })
} },
} }
return { return {
...store, ...store,