mirror of
https://github.com/grafana/grafana.git
synced 2025-09-28 18:54:25 +08:00
MultiCombobox: Show placeholder
when there is no options selected (#99743)
This commit is contained in:
@ -61,6 +61,17 @@ describe('MultiCombobox', () => {
|
|||||||
expect(screen.getByPlaceholderText('Select')).toBeInTheDocument();
|
expect(screen.getByPlaceholderText('Select')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not render with placeholder when options selected', async () => {
|
||||||
|
const options = [
|
||||||
|
{ label: 'A', value: 'a' },
|
||||||
|
{ label: 'B', value: 'b' },
|
||||||
|
{ label: 'C', value: 'c' },
|
||||||
|
];
|
||||||
|
render(<MultiCombobox options={options} value={['a']} onChange={jest.fn()} placeholder="Select" />);
|
||||||
|
const input = screen.getByRole('combobox');
|
||||||
|
expect(input).toHaveAttribute('placeholder', '');
|
||||||
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['a', 'b', 'c'],
|
['a', 'b', 'c'],
|
||||||
[1, 2, 3],
|
[1, 2, 3],
|
||||||
|
@ -276,7 +276,7 @@ export const MultiCombobox = <T extends string | number>(props: MultiComboboxPro
|
|||||||
getDropdownProps({
|
getDropdownProps({
|
||||||
disabled,
|
disabled,
|
||||||
preventKeyAction: isOpen,
|
preventKeyAction: isOpen,
|
||||||
placeholder,
|
placeholder: visibleItems.length === 0 ? placeholder : '',
|
||||||
ref: inputRef,
|
ref: inputRef,
|
||||||
style: { width: inputWidth },
|
style: { width: inputWidth },
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user