mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #21319 from overleaf/mj-select-controlled-null
[web] Allow Select to be controlled with no selection GitOrigin-RevId: 15e5b643e30205124f8e807379ab7e540e2145d1
This commit is contained in:
parent
792c9774a5
commit
4bc5a0f1d9
2 changed files with 10 additions and 2 deletions
|
@ -33,7 +33,7 @@ export type SelectProps<T> = {
|
||||||
defaultText?: string
|
defaultText?: string
|
||||||
// Initial selected item, displayed in the initial render. When both `defaultText`
|
// Initial selected item, displayed in the initial render. When both `defaultText`
|
||||||
// and `defaultItem` are set the latter is ignored.
|
// and `defaultItem` are set the latter is ignored.
|
||||||
defaultItem?: T
|
defaultItem?: T | null
|
||||||
// Stringifies an item. The resulting string is rendered as a subtitle in a dropdown option.
|
// Stringifies an item. The resulting string is rendered as a subtitle in a dropdown option.
|
||||||
itemToSubtitle?: (item: T | null | undefined) => string
|
itemToSubtitle?: (item: T | null | undefined) => string
|
||||||
// Stringifies an item. The resulting string is rendered as a React `key` for each item.
|
// Stringifies an item. The resulting string is rendered as a React `key` for each item.
|
||||||
|
@ -41,7 +41,7 @@ export type SelectProps<T> = {
|
||||||
// Callback invoked after the selected item is updated.
|
// Callback invoked after the selected item is updated.
|
||||||
onSelectedItemChanged?: (item: T | null | undefined) => void
|
onSelectedItemChanged?: (item: T | null | undefined) => void
|
||||||
// Optionally directly control the selected item.
|
// Optionally directly control the selected item.
|
||||||
selected?: T
|
selected?: T | null
|
||||||
// When `true` item selection is disabled.
|
// When `true` item selection is disabled.
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
// Determine which items should be disabled
|
// Determine which items should be disabled
|
||||||
|
|
|
@ -329,5 +329,13 @@ describe('<Select />', function () {
|
||||||
})
|
})
|
||||||
cy.findByText('Demo item 2').should('exist')
|
cy.findByText('Demo item 2').should('exist')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should show default text when selected is null', function () {
|
||||||
|
render({
|
||||||
|
selected: null,
|
||||||
|
defaultText: 'Choose an item',
|
||||||
|
})
|
||||||
|
cy.findByText('Choose an item').should('exist')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue