Skip to content

Commit

Permalink
fix: make selected values reactive #51
Browse files Browse the repository at this point in the history
  • Loading branch information
abichinger committed Apr 22, 2024
1 parent 0ae748b commit bbc5f85
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 52 deletions.
8 changes: 2 additions & 6 deletions ant/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import App from '@/App.vue'
import { Button, Col, Dropdown, Menu, Row } from 'ant-design-vue'
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'
import { createApp } from 'vue'

const app = createApp(App)
app.use(Button)
app.use(Dropdown)
app.use(Menu)
app.use(Row)
app.use(Col)
app.use(Antd)

app.mount('#app')
14 changes: 13 additions & 1 deletion core/src/components/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export function useSet<T>(options: SetOptions<T>) {
values,
add,
toggle,
has,
remove,
clear,
updated,
Expand Down Expand Up @@ -140,6 +139,18 @@ export function useSelect<T, V>(options: SelectOptions<T, V>) {
}
}

const has = (item: T | null): boolean => {
if (item === null) {
return false
}
const value = getValue(item)
if (Array.isArray(selected.value)) {
return selected.value.includes(value)
} else {
return selected.value === value
}
}

const getValue = (item: any): V => {
if (typeof itemValue == 'function') {
return itemValue(item)
Expand Down Expand Up @@ -193,6 +204,7 @@ export function useSelect<T, V>(options: SelectOptions<T, V>) {
setItems,
setValues,
isEmpty,
has,
}
}

Expand Down
43 changes: 11 additions & 32 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bbc5f85

Please sign in to comment.