Skip to content

Commit

Permalink
feat: table respects hidden & disabled, fix koishijs/koishi#1306
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Dec 29, 2023
1 parent e31cd3a commit e31df61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/form/src/extensions/table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
</th>
<th v-for="([key, schema]) in columns" :key="key">
<span>{{ key === null ? t('entry.value') : tt(schema.meta.description) || key }}</span>
<k-badge :type="type" v-for="{ text, type } in schema.meta.badges || []">
{{ t('badge.' + text) }}
</k-badge>
</th>
<th colspan="3"></th>
</tr>
Expand Down Expand Up @@ -50,7 +53,7 @@
<schema-primitive
minimal
:schema="schema"
:disabled="disabled"
:disabled="disabled || schema.meta.disabled"
:modelValue="key === null ? entries[i][1] : entries[i][1]?.[key]"
@update:modelValue="key === null ? entries[i][1] = $event : (entries[i][1] ||= {})[key] = $event"
@focus="handleFocus($event, i, j)"
Expand Down Expand Up @@ -162,6 +165,7 @@ function validateCell(i?: number, j?: number) {
function handleMouseEnter(event: MouseEvent, i?: number, j?: number) {
const el = event.target as HTMLElement
if (el === hover.value?.el) return
if (columns.value[j]?.[1].meta.disabled) return
hover.value = getRelative(el, validateCell(i, j))
}
Expand Down Expand Up @@ -226,16 +230,17 @@ if (import.meta.hot) {
th {
padding: 0.5rem 0.75rem;
line-height: 1rem;
line-height: 1.25rem;
}
td {
padding: 0;
* .el-input__wrapper {
box-shadow: none;
.el-input .el-input__wrapper {
box-shadow: none !important;
}
// override el-select !important rule
.el-select .el-input .el-input__wrapper {
box-shadow: none !important;
}
Expand Down
1 change: 1 addition & 0 deletions packages/form/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ function isValidColumn(schema: Schema): boolean {
}

function ensureColumns(entries: [string, Schema][]) {
entries = entries.filter(([, schema]) => !schema.meta.hidden)
if (entries.every(([, schema]) => isValidColumn(schema))) return entries
}

Expand Down

0 comments on commit e31df61

Please sign in to comment.