Skip to content

Commit

Permalink
fix(grid): [grid] fix can not select first option when value is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
gimmyhehe committed Jan 7, 2025
1 parent 6e29e24 commit 66af641
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions packages/vue/src/grid/src/adapter/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,32 @@ function getEvents(renderOpts, params, context) {
}

function renderOptions(h, options, renderOpts, params, context) {
let { optionProps = {} } = renderOpts
let labelProp = optionProps.label || 'label'
let valueProp = optionProps.value || 'value'
let { column, row } = params
let { formatConfig } = column.own
let cellValue = isSyncCell(renderOpts, params, context) ? getCellValue(row, column) : column.model.value
const { optionProps = {} } = renderOpts
const labelProp = optionProps.label || 'label'
const valueProp = optionProps.value || 'value'
const { column, row } = params
const { formatConfig } = column.own
const cellValue = isSyncCell(renderOpts, params, context) ? getCellValue(row, column) : column.model.value

if (!options && formatConfig && formatConfig.data) {
options = formatConfig.data
}

return options.map((item, index) => {
let attrs = {
domProps: { value: item[valueProp], selected: item.value === cellValue },
let hasSelected = false
const optionsList = options.map((item, index) => {
const selected = item.value === cellValue
if (selected) {
hasSelected = true
}
const attrs = {
domProps: { value: item[valueProp], selected },
key: index
}
return h('option', attrs, item[labelProp])
})
if (options.length && !hasSelected) {
optionsList.unshift(h('option', { style: 'display:none', selected: true }, ''))
}
return optionsList
}

function renderOptgroups(h, options, params, context) {
Expand Down

0 comments on commit 66af641

Please sign in to comment.