mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Select: Add data-testid to Input (#87105)
* Select: Add custom input component * Forward data-testid * Add input selector * Props check
This commit is contained in:
@@ -72,9 +72,9 @@ describe('Loki query builder', () => {
|
||||
// Add labels to remove error
|
||||
e2e.components.QueryBuilder.labelSelect().should('be.visible').click();
|
||||
// wait until labels are loaded and set on the component before starting to type
|
||||
e2e.components.QueryBuilder.labelSelect().children('div').children('input').type('i');
|
||||
e2e.components.QueryBuilder.inputSelect().type('i');
|
||||
cy.wait('@labelsRequest');
|
||||
e2e.components.QueryBuilder.labelSelect().children('div').children('input').type('nstance{enter}');
|
||||
e2e.components.QueryBuilder.inputSelect().type('nstance{enter}');
|
||||
e2e.components.QueryBuilder.matchOperatorSelect()
|
||||
.should('be.visible')
|
||||
.click({ force: true })
|
||||
|
||||
@@ -452,6 +452,7 @@ export const Components = {
|
||||
QueryBuilder: {
|
||||
queryPatterns: 'data-testid Query patterns',
|
||||
labelSelect: 'data-testid Select label',
|
||||
inputSelect: 'data-testid Select label-input',
|
||||
valueSelect: 'data-testid Select value',
|
||||
matchOperatorSelect: 'data-testid Select match operator',
|
||||
},
|
||||
|
||||
15
packages/grafana-ui/src/components/Select/CustomInput.tsx
Normal file
15
packages/grafana-ui/src/components/Select/CustomInput.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
import { components, InputProps } from 'react-select';
|
||||
|
||||
/**
|
||||
* Custom input component for react-select to add data-testid attribute
|
||||
*/
|
||||
export const CustomInput = (props: InputProps) => {
|
||||
let testId;
|
||||
|
||||
if ('data-testid' in props.selectProps && props.selectProps['data-testid']) {
|
||||
testId = props.selectProps['data-testid'] + '-input';
|
||||
}
|
||||
|
||||
return <components.Input {...props} data-testid={testId} />;
|
||||
};
|
||||
@@ -11,6 +11,7 @@ import { useTheme2 } from '../../themes';
|
||||
import { Icon } from '../Icon/Icon';
|
||||
import { Spinner } from '../Spinner/Spinner';
|
||||
|
||||
import { CustomInput } from './CustomInput';
|
||||
import { DropdownIndicator } from './DropdownIndicator';
|
||||
import { IndicatorsContainer } from './IndicatorsContainer';
|
||||
import { InputControl } from './InputControl';
|
||||
@@ -330,6 +331,7 @@ export function SelectBase<T, Rest = {}>({
|
||||
SelectContainer,
|
||||
MultiValueContainer: MultiValueContainer,
|
||||
MultiValueRemove: !disabled ? MultiValueRemove : () => null,
|
||||
Input: CustomInput,
|
||||
...components,
|
||||
}}
|
||||
styles={selectStyles}
|
||||
|
||||
Reference in New Issue
Block a user