Select: Fix issue with placeholder and auto width (#42851)
* Select: Fix issue with placeholder and auto width * Fixed lint issue
This commit is contained in:
@@ -15,7 +15,8 @@ import NoOptionsMessage from './NoOptionsMessage';
|
||||
import resetSelectStyles from '../../../Select/resetSelectStyles';
|
||||
import { CustomScrollbar } from '../../../CustomScrollbar/CustomScrollbar';
|
||||
import { PopoverContent, Tooltip } from '../../../Tooltip/Tooltip';
|
||||
import { SelectableValue } from '@grafana/data';
|
||||
import { GrafanaTheme2, SelectableValue } from '@grafana/data';
|
||||
import { ThemeContext } from '../../../../themes';
|
||||
|
||||
/**
|
||||
* Changes in new selects:
|
||||
@@ -49,6 +50,8 @@ export const MenuList = (props: any) => {
|
||||
);
|
||||
};
|
||||
export class Select<T> extends PureComponent<LegacySelectProps<T>> {
|
||||
static contextType = ThemeContext;
|
||||
|
||||
static defaultProps: Partial<LegacySelectProps<any>> = {
|
||||
className: '',
|
||||
isDisabled: false,
|
||||
@@ -137,7 +140,7 @@ export class Select<T> extends PureComponent<LegacySelectProps<T>> {
|
||||
onChange={onChange}
|
||||
options={options}
|
||||
placeholder={placeholder || 'Choose'}
|
||||
styles={resetSelectStyles()}
|
||||
styles={resetSelectStyles(this.context as GrafanaTheme2)}
|
||||
isDisabled={isDisabled}
|
||||
isLoading={isLoading}
|
||||
isClearable={isClearable}
|
||||
|
||||
@@ -6,7 +6,6 @@ import { default as AsyncCreatable } from 'react-select/async-creatable';
|
||||
|
||||
import { Icon } from '../Icon/Icon';
|
||||
import { Spinner } from '../Spinner/Spinner';
|
||||
import { css, cx } from '@emotion/css';
|
||||
import resetSelectStyles from './resetSelectStyles';
|
||||
import { SelectMenu, SelectMenuOptions } from './SelectMenu';
|
||||
import { IndicatorsContainer } from './IndicatorsContainer';
|
||||
@@ -251,33 +250,6 @@ export function SelectBase<T>({
|
||||
MenuList: SelectMenu,
|
||||
Group: SelectOptionGroup,
|
||||
ValueContainer,
|
||||
Placeholder(props: any) {
|
||||
return (
|
||||
<div
|
||||
{...props.innerProps}
|
||||
className={cx(
|
||||
css(props.getStyles('placeholder', props)),
|
||||
css`
|
||||
display: inline-block;
|
||||
color: ${theme.colors.text.disabled};
|
||||
grid-area: 1 / 1 / 2 / 3;
|
||||
box-sizing: border-box;
|
||||
line-height: 1;
|
||||
white-space: nowrap;
|
||||
`,
|
||||
// When width: auto, the placeholder must take up space in the Select otherwise the width collapses down
|
||||
width !== 'auto' &&
|
||||
css`
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
`
|
||||
)}
|
||||
>
|
||||
{props.children}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
IndicatorsContainer(props: any) {
|
||||
const { selectProps } = props;
|
||||
const { value, showAllSelectedWhenOpen, maxVisibleValues, menuIsOpen } = selectProps;
|
||||
@@ -346,7 +318,7 @@ export function SelectBase<T>({
|
||||
...components,
|
||||
}}
|
||||
styles={{
|
||||
...resetSelectStyles(),
|
||||
...resetSelectStyles(theme),
|
||||
menuPortal: (base: any) => ({
|
||||
...base,
|
||||
zIndex: theme.zIndex.portal,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { CSSObjectWithLabel } from 'react-select';
|
||||
|
||||
export default function resetSelectStyles() {
|
||||
export default function resetSelectStyles(theme: GrafanaTheme2) {
|
||||
return {
|
||||
clearIndicator: () => ({}),
|
||||
container: () => ({}),
|
||||
@@ -31,7 +32,10 @@ export default function resetSelectStyles() {
|
||||
multiValueRemove: () => ({}),
|
||||
noOptionsMessage: () => ({}),
|
||||
option: () => ({}),
|
||||
placeholder: () => ({}),
|
||||
placeholder: (originalStyles: CSSObjectWithLabel) => ({
|
||||
...originalStyles,
|
||||
color: theme.colors.text.disabled,
|
||||
}),
|
||||
singleValue: () => ({}),
|
||||
valueContainer: () => ({}),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user