Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Emotion] Convert EuiTextArea, EuiSelect, and EuiSuperSelect #7812

Merged
merged 16 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/eui/src/components/form/select/select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('EuiSelect', () => {
>

</option>
`);
`);
});

it('can be reset to an empty initial selection', () => {
Expand Down
46 changes: 21 additions & 25 deletions packages/eui/src/components/form/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import React, {
OptionHTMLAttributes,
Ref,
FunctionComponent,
useCallback,
} from 'react';
import classNames from 'classnames';

Expand Down Expand Up @@ -100,14 +101,21 @@ export const EuiSelect: FunctionComponent<EuiSelectProps> = (props) => {
// value needs to fallback to an empty string to interact properly with `defaultValue`
const value = hasNoInitialSelection ? _value ?? '' : _value;

const handleMouseUp = (e: React.MouseEvent<HTMLSelectElement>) => {
// Normalizes cross-browser mouse eventing by preventing propagation,
// notably for use in conjunction with EuiOutsideClickDetector.
// See https://github.com/elastic/eui/pull/1926 for full discussion on
// rationale and alternatives should this intervention become problematic.
e.nativeEvent.stopImmediatePropagation();
if (onMouseUp) onMouseUp(e);
};
// React HTML input can not have both value and defaultValue properties.
// https://reactjs.org/docs/uncontrolled-components.html#default-values
const selectDefaultValue = value != null ? undefined : defaultValue || '';

const handleMouseUp = useCallback(
(e: React.MouseEvent<HTMLSelectElement>) => {
// Normalizes cross-browser mouse eventing by preventing propagation,
// notably for use in conjunction with EuiOutsideClickDetector.
// See https://github.com/elastic/eui/pull/1926 for full discussion on
// rationale and alternatives should this intervention become problematic.
e.nativeEvent.stopImmediatePropagation();
onMouseUp?.(e);
},
[onMouseUp]
);

const classes = classNames(
'euiSelect',
Expand All @@ -133,22 +141,6 @@ export const EuiSelect: FunctionComponent<EuiSelectProps> = (props) => {
: styles.lineHeight.uncompressed,
];

let emptyOptionNode;
if (hasNoInitialSelection) {
emptyOptionNode = (
<option value="" disabled hidden style={{ display: 'none' }}>
&nbsp;
</option>
);
}

// React HTML input can not have both value and defaultValue properties.
// https://reactjs.org/docs/uncontrolled-components.html#default-values
let selectDefaultValue;
if (value == null) {
selectDefaultValue = defaultValue || '';
}

return (
<EuiFormControlLayout
isDropdown={true}
Expand All @@ -174,7 +166,11 @@ export const EuiSelect: FunctionComponent<EuiSelectProps> = (props) => {
disabled={disabled}
{...rest}
>
{emptyOptionNode}
{hasNoInitialSelection && (
cee-chen marked this conversation as resolved.
Show resolved Hide resolved
<option value="" disabled hidden style={{ display: 'none' }}>
&nbsp;
</option>
)}
{options.map((option, index) => {
const { text, ...rest } = option;
return (
Expand Down