-
-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pre-selected option to selecto? #129
Comments
selecto has setSelectedTargets method. If you want it to be preselected, call |
Would you mind providing a snippet of how you hook it up in Selecto component? Thank you! |
I actually could not use the setSelectedTargers() so I decided to add selected class into the div by myself. Here is how I did it if you are curious: |
I used <script setup lang="ts">
import { onMounted, ref } from "vue";
import Selecto from "vue3-selecto";
import { SelectedTargets } from "selecto";
const selecto = ref<Selecto>();
function onSelect(e: SelectedTargets) {
console.log(e);
e.added.forEach(el => {
el.style.background = "#f55";
});
e.removed.forEach(el => {
el.style.background = "transparent";
});
}
onMounted(() => {
const result = selecto.value!.setSelectedTargets([document.querySelector("img")!]);
onSelect(result);
});
const dragContainer = typeof window !== "undefined" && window as Window;
</script>
<template>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="/vite.svg" class="logo" alt="Vite logo" />
</a>
<a href="https://vuejs.org/" target="_blank">
<img src="./assets/vue.svg" class="logo vue" alt="Vue logo" />
</a>
</div>
<Selecto ref="selecto" @select-end="onSelect" :drag-container="dragContainer" :selectable-targets="['img']"/>
</template> |
Environments
Description
I wonder if there is a way I can pass in an array of the coordinate of each box and have it to be pre-selected. For example, if I have a selection area of 10 boxes, I could target a box with its id and make it to be selected. As I look at the documentation, I don't think this option is available yet.
For example, I can configure selecto so that the box "1" to be already selected at the beginning.
Thank you for making such an awesome package so far.
The text was updated successfully, but these errors were encountered: