Skip to content
Merged
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added exports for all EUI component props matching `EuiComponentProps` name pattern. ([#4517](https://github.com/elastic/eui/pull/4517))
Comment thread
akashgp09 marked this conversation as resolved.
Outdated
- Added `truncate`, `disabled`, and `emphasize` props to `EuiSideNavItem` ([#4488](https://github.com/elastic/eui/pull/4488))
- Added `truncate` prop to `EuiSideNav` ([#4488](https://github.com/elastic/eui/pull/4488))
- Reverted part of [#4509](https://github.com/elastic/eui/pull/4509) and returned `EuiDataGrid`'s background content area to an empty shade ([#4542](https://github.com/elastic/eui/pull/4542))
- Reverted part of [#4509](https://github.com/elastic/eui/pull/4509) and returned `EuiDataGrid`'s background content area to an empty shade ([#4542](https://github.com/elastic/eui/pull/4542))
- Added exports for all EUI component props matching `EuiComponentProps` name pattern. ([#4517](https://github.com/elastic/eui/pull/4517))
- Added `truncate`, `disabled`, and `emphasize` props to `EuiSideNavItem` ([#4488](https://github.com/elastic/eui/pull/4488))
Expand Down
110 changes: 58 additions & 52 deletions src/components/call_out/call_out.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import React, { FunctionComponent, HTMLAttributes, ReactNode } from 'react';
import React, { forwardRef, Ref, HTMLAttributes, ReactNode } from 'react';

import classNames from 'classnames';

Expand Down Expand Up @@ -54,59 +54,65 @@ const sizeToClassNameMap: { [size in Size]: string } = {
m: '',
};

export const EuiCallOut: FunctionComponent<EuiCallOutProps> = ({
title,
color = 'primary',
size = 'm',
iconType,
children,
className,
heading,
...rest
}) => {
const classes = classNames(
'euiCallOut',
colorToClassNameMap[color],
sizeToClassNameMap[size],
className
);

let headerIcon;

if (iconType) {
headerIcon = (
<EuiIcon
className="euiCallOutHeader__icon"
type={iconType}
size="m"
aria-hidden="true"
/>
export const EuiCallOut = forwardRef<HTMLDivElement, EuiCallOutProps>(
(
{
title,
color = 'primary',
size = 'm',
iconType,
children,
className,
heading,
...rest
},
ref: Ref<HTMLDivElement>
) => {
const classes = classNames(
'euiCallOut',
colorToClassNameMap[color],
sizeToClassNameMap[size],
className
);
}

let optionalChildren;
if (children && size === 's') {
optionalChildren = <EuiText size="xs">{children}</EuiText>;
} else if (children) {
optionalChildren = <EuiText size="s">{children}</EuiText>;
}

const H: any = heading ? `${heading}` : 'span';
let header;

if (title) {
header = (
<div className="euiCallOutHeader">
{headerIcon}
<H className="euiCallOutHeader__title">{title}</H>
let headerIcon;

if (iconType) {
headerIcon = (
<EuiIcon
className="euiCallOutHeader__icon"
type={iconType}
size="m"
aria-hidden="true"
/>
);
}

let optionalChildren;
if (children && size === 's') {
optionalChildren = <EuiText size="xs">{children}</EuiText>;
} else if (children) {
optionalChildren = <EuiText size="s">{children}</EuiText>;
}

const H: any = heading ? `${heading}` : 'span';
let header;

if (title) {
header = (
<div className="euiCallOutHeader">
{headerIcon}
<H className="euiCallOutHeader__title">{title}</H>
</div>
);
}
return (
<div className={classes} ref={ref} {...rest}>
{header}

{optionalChildren}
</div>
);
}
return (
<div className={classes} {...rest}>
{header}

{optionalChildren}
</div>
);
};
);
EuiCallOut.displayName = 'EuiCallOut';
3 changes: 3 additions & 0 deletions src/components/form/__snapshots__/form.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ exports[`EuiForm renders with error callout when isInvalid is "true" 1`] = `
aria-live="assertive"
class="euiCallOut euiCallOut--danger euiForm__errors"
role="alert"
tabindex="-1"
>
<div
class="euiCallOutHeader"
Expand All @@ -50,6 +51,7 @@ exports[`EuiForm renders with error callout when isInvalid is "true" and has mul
aria-live="assertive"
class="euiCallOut euiCallOut--danger euiForm__errors"
role="alert"
tabindex="-1"
>
<div
class="euiCallOutHeader"
Expand Down Expand Up @@ -94,6 +96,7 @@ exports[`EuiForm renders with error callout when isInvalid is "true" and has one
aria-live="assertive"
class="euiCallOut euiCallOut--danger euiForm__errors"
role="alert"
tabindex="-1"
>
<div
class="euiCallOutHeader"
Expand Down
4 changes: 4 additions & 0 deletions src/components/form/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export const EuiForm: FunctionComponent<EuiFormProps> = ({
default="Please address the highlighted errors.">
{(addressFormErrors: string) => (
<EuiCallOut
tabIndex={-1}
ref={(node) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting. Because it creates the new ref function every render pass, it will re-focus the element every time and not only first mount. I imagine this will be aggravating in cases when the user tries to edit an invalid field, but we'll test what happens in practice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we need to focus the element only once, for the first mount ?
We can accomplish this by setting focus to the Element inside useEffect hook 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this by adding a setState to track the value of the example's textarea, and not only does the screen scroll back to the error box, but it takes focus off the textarea so I had to click back into it for each character. Either a useEffect, or moving the function passed to ref into a useCallback, should help clear that up.

form_validation_test

node && node.focus();
}}
className="euiForm__errors"
title={addressFormErrors}
color="danger"
Expand Down