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 resetSelectStyles from '../../../Select/resetSelectStyles';
|
||||||
import { CustomScrollbar } from '../../../CustomScrollbar/CustomScrollbar';
|
import { CustomScrollbar } from '../../../CustomScrollbar/CustomScrollbar';
|
||||||
import { PopoverContent, Tooltip } from '../../../Tooltip/Tooltip';
|
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:
|
* Changes in new selects:
|
||||||
@@ -49,6 +50,8 @@ export const MenuList = (props: any) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
export class Select<T> extends PureComponent<LegacySelectProps<T>> {
|
export class Select<T> extends PureComponent<LegacySelectProps<T>> {
|
||||||
|
static contextType = ThemeContext;
|
||||||
|
|
||||||
static defaultProps: Partial<LegacySelectProps<any>> = {
|
static defaultProps: Partial<LegacySelectProps<any>> = {
|
||||||
className: '',
|
className: '',
|
||||||
isDisabled: false,
|
isDisabled: false,
|
||||||
@@ -137,7 +140,7 @@ export class Select<T> extends PureComponent<LegacySelectProps<T>> {
|
|||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
options={options}
|
options={options}
|
||||||
placeholder={placeholder || 'Choose'}
|
placeholder={placeholder || 'Choose'}
|
||||||
styles={resetSelectStyles()}
|
styles={resetSelectStyles(this.context as GrafanaTheme2)}
|
||||||
isDisabled={isDisabled}
|
isDisabled={isDisabled}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
isClearable={isClearable}
|
isClearable={isClearable}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import { default as AsyncCreatable } from 'react-select/async-creatable';
|
|||||||
|
|
||||||
import { Icon } from '../Icon/Icon';
|
import { Icon } from '../Icon/Icon';
|
||||||
import { Spinner } from '../Spinner/Spinner';
|
import { Spinner } from '../Spinner/Spinner';
|
||||||
import { css, cx } from '@emotion/css';
|
|
||||||
import resetSelectStyles from './resetSelectStyles';
|
import resetSelectStyles from './resetSelectStyles';
|
||||||
import { SelectMenu, SelectMenuOptions } from './SelectMenu';
|
import { SelectMenu, SelectMenuOptions } from './SelectMenu';
|
||||||
import { IndicatorsContainer } from './IndicatorsContainer';
|
import { IndicatorsContainer } from './IndicatorsContainer';
|
||||||
@@ -251,33 +250,6 @@ export function SelectBase<T>({
|
|||||||
MenuList: SelectMenu,
|
MenuList: SelectMenu,
|
||||||
Group: SelectOptionGroup,
|
Group: SelectOptionGroup,
|
||||||
ValueContainer,
|
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) {
|
IndicatorsContainer(props: any) {
|
||||||
const { selectProps } = props;
|
const { selectProps } = props;
|
||||||
const { value, showAllSelectedWhenOpen, maxVisibleValues, menuIsOpen } = selectProps;
|
const { value, showAllSelectedWhenOpen, maxVisibleValues, menuIsOpen } = selectProps;
|
||||||
@@ -346,7 +318,7 @@ export function SelectBase<T>({
|
|||||||
...components,
|
...components,
|
||||||
}}
|
}}
|
||||||
styles={{
|
styles={{
|
||||||
...resetSelectStyles(),
|
...resetSelectStyles(theme),
|
||||||
menuPortal: (base: any) => ({
|
menuPortal: (base: any) => ({
|
||||||
...base,
|
...base,
|
||||||
zIndex: theme.zIndex.portal,
|
zIndex: theme.zIndex.portal,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import { GrafanaTheme2 } from '@grafana/data';
|
||||||
import { CSSObjectWithLabel } from 'react-select';
|
import { CSSObjectWithLabel } from 'react-select';
|
||||||
|
|
||||||
export default function resetSelectStyles() {
|
export default function resetSelectStyles(theme: GrafanaTheme2) {
|
||||||
return {
|
return {
|
||||||
clearIndicator: () => ({}),
|
clearIndicator: () => ({}),
|
||||||
container: () => ({}),
|
container: () => ({}),
|
||||||
@@ -31,7 +32,10 @@ export default function resetSelectStyles() {
|
|||||||
multiValueRemove: () => ({}),
|
multiValueRemove: () => ({}),
|
||||||
noOptionsMessage: () => ({}),
|
noOptionsMessage: () => ({}),
|
||||||
option: () => ({}),
|
option: () => ({}),
|
||||||
placeholder: () => ({}),
|
placeholder: (originalStyles: CSSObjectWithLabel) => ({
|
||||||
|
...originalStyles,
|
||||||
|
color: theme.colors.text.disabled,
|
||||||
|
}),
|
||||||
singleValue: () => ({}),
|
singleValue: () => ({}),
|
||||||
valueContainer: () => ({}),
|
valueContainer: () => ({}),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useCallback, useMemo, useState } from 'react';
|
import React, { useCallback, useMemo, useState } from 'react';
|
||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import debounce from 'debounce-promise';
|
import debounce from 'debounce-promise';
|
||||||
import { AsyncMultiSelect, Icon, resetSelectStyles, useStyles2 } from '@grafana/ui';
|
import { AsyncMultiSelect, Icon, useStyles2 } from '@grafana/ui';
|
||||||
import { GrafanaTheme2, SelectableValue } from '@grafana/data';
|
import { GrafanaTheme2, SelectableValue } from '@grafana/data';
|
||||||
|
|
||||||
import { FolderInfo, PermissionLevelString } from 'app/types';
|
import { FolderInfo, PermissionLevelString } from 'app/types';
|
||||||
@@ -36,7 +36,6 @@ export function FolderFilter({ onChange: propsOnChange, maxMenuHeight }: FolderF
|
|||||||
isMulti: true,
|
isMulti: true,
|
||||||
noOptionsMessage: 'No folders found',
|
noOptionsMessage: 'No folders found',
|
||||||
placeholder: 'Filter by folder',
|
placeholder: 'Filter by folder',
|
||||||
styles: resetSelectStyles(),
|
|
||||||
maxMenuHeight,
|
maxMenuHeight,
|
||||||
value,
|
value,
|
||||||
onChange,
|
onChange,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useCallback, useMemo, useState } from 'react';
|
import React, { useCallback, useMemo, useState } from 'react';
|
||||||
import { GrafanaTheme2, PanelPluginMeta, SelectableValue } from '@grafana/data';
|
import { GrafanaTheme2, PanelPluginMeta, SelectableValue } from '@grafana/data';
|
||||||
import { getAllPanelPluginMeta } from 'app/features/panel/state/util';
|
import { getAllPanelPluginMeta } from 'app/features/panel/state/util';
|
||||||
import { Icon, resetSelectStyles, MultiSelect, useStyles2 } from '@grafana/ui';
|
import { Icon, MultiSelect, useStyles2 } from '@grafana/ui';
|
||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
@@ -42,7 +42,6 @@ export const PanelTypeFilter = ({ onChange: propsOnChange, maxMenuHeight }: Prop
|
|||||||
getOptionValue: (i: any) => i.value,
|
getOptionValue: (i: any) => i.value,
|
||||||
noOptionsMessage: 'No Panel types found',
|
noOptionsMessage: 'No Panel types found',
|
||||||
placeholder: 'Filter by type',
|
placeholder: 'Filter by type',
|
||||||
styles: resetSelectStyles(),
|
|
||||||
maxMenuHeight,
|
maxMenuHeight,
|
||||||
options,
|
options,
|
||||||
value,
|
value,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import React, { FC } from 'react';
|
|||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import { components } from 'react-select';
|
import { components } from 'react-select';
|
||||||
import debounce from 'debounce-promise';
|
import debounce from 'debounce-promise';
|
||||||
import { stylesFactory, useTheme, resetSelectStyles, Icon, AsyncMultiSelect } from '@grafana/ui';
|
import { stylesFactory, useTheme, Icon, AsyncMultiSelect } from '@grafana/ui';
|
||||||
import { escapeStringForRegex, GrafanaTheme } from '@grafana/data';
|
import { escapeStringForRegex, GrafanaTheme } from '@grafana/data';
|
||||||
// Components
|
// Components
|
||||||
import { TagOption } from './TagOption';
|
import { TagOption } from './TagOption';
|
||||||
@@ -82,7 +82,6 @@ export const TagFilter: FC<Props> = ({
|
|||||||
noOptionsMessage: 'No tags found',
|
noOptionsMessage: 'No tags found',
|
||||||
onChange: onTagChange,
|
onChange: onTagChange,
|
||||||
placeholder,
|
placeholder,
|
||||||
styles: resetSelectStyles(),
|
|
||||||
value,
|
value,
|
||||||
width,
|
width,
|
||||||
components: {
|
components: {
|
||||||
|
|||||||
Reference in New Issue
Block a user