Skip to content

Commit

Permalink
[EuiSelect] & [EuiSuperSelect] Update to new EuiFormControlLayout props
Browse files Browse the repository at this point in the history
- Fixed EuiSuperSelect border radius with append/prepend elastic#5442
- Fixed EuiSuperSelect not respecting `readOnly` elastic#3510
  • Loading branch information
cchaos committed Mar 22, 2022
1 parent fdca711 commit dd3bdac
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src-docs/src/views/form_controls/display_toggles.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const DisplayToggles = ({
compressed{' '}
<EuiToolTip content="Compressed usages are very specific. Click to view full compressed documentation">
<a href="#/forms/compressed-forms">
<EuiIcon type="help" />
<EuiIcon type="help" aria-label="help" />
</a>
</EuiToolTip>
</span>
Expand Down
4 changes: 3 additions & 1 deletion src/components/form/form_control_layout/_num_icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ export type _EuiFormControlLayoutNumIcons = {
clear?: boolean;
isLoading?: boolean;
isInvalid?: boolean;
isDropdown?: boolean;
};

export function getFormControlClassNameForIconCount({
icon,
clear,
isLoading,
isInvalid,
isDropdown,
}: _EuiFormControlLayoutNumIcons): string | undefined {
const numIcons = [icon, clear, isInvalid, isLoading].filter(
const numIcons = [icon, clear, isInvalid, isLoading, isDropdown].filter(
(item) => item === true
).length;

Expand Down
14 changes: 7 additions & 7 deletions src/components/form/select/__snapshots__/select.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ exports[`EuiSelect is rendered 1`] = `
<eui-form-control-layout
compressed="false"
fullwidth="false"
icon="[object Object]"
inputid="id"
isdropdown="true"
isloading="false"
>
<eui-validatable-control>
Expand All @@ -24,7 +24,7 @@ exports[`EuiSelect props disabled options are rendered 1`] = `
<eui-form-control-layout
compressed="false"
fullwidth="false"
icon="[object Object]"
isdropdown="true"
isloading="false"
>
<eui-validatable-control>
Expand All @@ -51,7 +51,7 @@ exports[`EuiSelect props fullWidth is rendered 1`] = `
<eui-form-control-layout
compressed="false"
fullwidth="true"
icon="[object Object]"
isdropdown="true"
isloading="false"
>
<eui-validatable-control>
Expand All @@ -66,7 +66,7 @@ exports[`EuiSelect props isInvalid is rendered 1`] = `
<eui-form-control-layout
compressed="false"
fullwidth="false"
icon="[object Object]"
isdropdown="true"
isinvalid="true"
isloading="false"
>
Expand All @@ -84,7 +84,7 @@ exports[`EuiSelect props isLoading is rendered 1`] = `
<eui-form-control-layout
compressed="false"
fullwidth="false"
icon="[object Object]"
isdropdown="true"
isloading="true"
>
<eui-validatable-control>
Expand All @@ -99,7 +99,7 @@ exports[`EuiSelect props options are rendered 1`] = `
<eui-form-control-layout
compressed="false"
fullwidth="false"
icon="[object Object]"
isdropdown="true"
isloading="false"
>
<eui-validatable-control>
Expand All @@ -125,7 +125,7 @@ exports[`EuiSelect props value option is rendered 1`] = `
<eui-form-control-layout
compressed="false"
fullwidth="false"
icon="[object Object]"
isdropdown="true"
isloading="false"
>
<eui-validatable-control>
Expand Down
5 changes: 4 additions & 1 deletion src/components/form/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const EuiSelect: FunctionComponent<EuiSelectProps> = ({
prepend,
append,
onMouseUp,
disabled,
...rest
}) => {
// if this is injecting an empty option for `hasNoInitialSelection` then
Expand Down Expand Up @@ -133,10 +134,11 @@ export const EuiSelect: FunctionComponent<EuiSelectProps> = ({

return (
<EuiFormControlLayout
icon={icon}
isDropdown={true}
fullWidth={fullWidth}
isLoading={isLoading}
isInvalid={isInvalid}
isDisabled={disabled}
compressed={compressed}
prepend={prepend}
append={append}
Expand All @@ -151,6 +153,7 @@ export const EuiSelect: FunctionComponent<EuiSelectProps> = ({
defaultValue={selectDefaultValue}
value={value}
onMouseUp={handleMouseUp}
disabled={disabled}
{...rest}
>
{emptyOptionNode}
Expand Down
17 changes: 10 additions & 7 deletions src/components/form/super_select/super_select_control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,20 @@ export const EuiSuperSelectControl: <T extends string>(
fullWidth = false,
isLoading = false,
isInvalid = false,
readOnly,
defaultValue,
compressed = false,
value,
prepend,
append,
screenReaderId,
disabled,
...rest
}) => {
const numIconsClass = getFormControlClassNameForIconCount({
icon: true,
isInvalid,
isLoading,
isDropdown: true,
});

const classes = classNames(
Expand Down Expand Up @@ -116,11 +118,6 @@ export const EuiSuperSelectControl: <T extends string>(
: selectedValue;
}

const icon: EuiFormControlLayoutProps['icon'] = {
type: 'arrowDown',
side: 'right',
};

return (
<Fragment>
<input
Expand All @@ -129,13 +126,16 @@ export const EuiSuperSelectControl: <T extends string>(
name={name}
defaultValue={selectDefaultValue}
value={value}
readOnly={readOnly}
/>

<EuiFormControlLayout
icon={icon}
isDropdown
fullWidth={fullWidth}
isLoading={isLoading}
isInvalid={isInvalid}
isDisabled={disabled}
readOnly={readOnly}
compressed={compressed}
prepend={prepend}
append={append}
Expand All @@ -157,6 +157,9 @@ export const EuiSuperSelectControl: <T extends string>(
type="button"
className={classes}
aria-haspopup="listbox"
disabled={disabled || readOnly}
// @ts-ignore Using as a selector only for mixin use
readOnly={readOnly}
{...rest}
>
{selectedValue}
Expand Down
3 changes: 3 additions & 0 deletions src/global_styling/mixins/_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@
}

@mixin euiFormControlReadOnlyStyle {
// sass-lint:disable-block no-vendor-prefixes
cursor: default;
color: $euiTextColor;
-webkit-text-fill-color: $euiTextColor; // Required for Safari
// Use transparency since there is no border and in case form is on a non-white background
background: $euiFormBackgroundReadOnlyColor;
border-color: transparent;
Expand Down
2 changes: 2 additions & 0 deletions src/themes/amsterdam/overrides/_form_control_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@
}

.euiFormControlLayout__childrenWrapper:first-child .euiSelect,
.euiFormControlLayout__childrenWrapper:first-child .euiSuperSelectControl,
.euiFormControlLayout__childrenWrapper:first-child [class*='euiField'] {
@include euiFormControlSideBorderRadius($euiFormControlBorderRadius, $side: 'left');
}

.euiFormControlLayout__childrenWrapper:last-child .euiSelect,
.euiFormControlLayout__childrenWrapper:last-child .euiSuperSelectControl,
.euiFormControlLayout__childrenWrapper:last-child [class*='euiField'] {
@include euiFormControlSideBorderRadius($euiFormControlBorderRadius, $side: 'right');
}
Expand Down

0 comments on commit dd3bdac

Please sign in to comment.