Focus input when added via add button

This commit is contained in:
Lea Verou
2025-03-17 10:09:21 -04:00
parent 08bf971f91
commit 7c04550753
3 changed files with 14 additions and 2 deletions

View File

@@ -887,7 +887,7 @@ let paletteAppSpec = {
}
},
addColor(value) {
addColor(value, options) {
if (!value) {
if (this.seedColors.length === 0) {
value = firstSeedColor;
@@ -917,6 +917,10 @@ let paletteAppSpec = {
value = { value: value + '', color: value };
}
if (options) {
Object.assign(value, options);
}
value.uid ??= this.maxSeedUid++;
this.seedColors.push(value);
},

View File

@@ -124,6 +124,14 @@ export default {
// Non-reactive variables to expose
Object.assign(this, { ROLES, allHues });
},
async mounted() {
if (this.modelValue.editImmediately) {
let input = this.$refs.input;
await input.updateComplete;
input.focus();
input.select();
}
},
computed: {
inputLCH() {
return this.inputColor?.oklch;

View File

@@ -18,7 +18,7 @@ status: experimental
@update:roles="roles => setColorRole(i, roles)"
@delete="deleteColor(i)"></color-input>
</template>
<wa-button class="add-button" appearance="outlined" @click="addColor()">
<wa-button class="add-button" appearance="outlined" @click="addColor(undefined, {editImmediately: true})">
<wa-icon slot="prefix" name="plus" variant="regular"></wa-icon>
<span v-content="step > 0 ? 'Add color' : 'New palette'">New palette</span>
</wa-button>