Skip to content

Commit 3faccaa

Browse files
committed
Address previous TODO / have EuiFormLayout set the icon affordance CSS variables on wrapper
- while accounting for EuiFormLayoutDelineated's static icons
1 parent eafa7f1 commit 3faccaa

5 files changed

Lines changed: 22 additions & 24 deletions

File tree

packages/eui/src-docs/src/views/form_controls/form_controls_example.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -477,16 +477,6 @@ export const FormControlsExample = {
477477
the <EuiCode>controlOnly</EuiCode> and <EuiCode>type</EuiCode> props
478478
of <strong>EuiFieldText</strong> as the wrapped control.
479479
</p>
480-
481-
<EuiCallOut title="Additional padding required" color="warning">
482-
<p>
483-
The padding on the <EuiCode>input</EuiCode> itself doesn&rsquo;t
484-
take into account the presence of the various icons supported by{' '}
485-
<strong>EuiFormControlLayout</strong>. Any input component
486-
provided to <strong>EuiFormControlLayout</strong> is responsible
487-
for its own padding.
488-
</p>
489-
</EuiCallOut>
490480
</>
491481
),
492482
props: {

packages/eui/src/components/date_picker/date_picker.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { Moment } from 'moment'; // eslint-disable-line import/named
2121

2222
import { EuiFormControlLayout, useEuiValidatableControl } from '../form';
2323
import { EuiFormControlLayoutIconsProps } from '../form/form_control_layout/form_control_layout_icons';
24-
import { getIconAffordanceStyles } from '../form/form_control_layout/_num_icons';
2524

2625
import { useCombinedRefs } from '../../services';
2726
import { EuiI18nConsumer } from '../context';
@@ -282,16 +281,6 @@ export const EuiDatePicker: FunctionComponent<EuiDatePickerProps> = ({
282281
optionalIcon = 'calendar';
283282
}
284283

285-
// TODO: DRY out icon affordance logic to EuiFormControlLayout in the next few PRs
286-
const iconAffordanceStyles = !controlOnly
287-
? getIconAffordanceStyles({
288-
icon: optionalIcon,
289-
clear: !!(selected && onClear),
290-
isInvalid,
291-
isLoading,
292-
})
293-
: undefined;
294-
295284
return (
296285
<span className={classes}>
297286
<EuiFormControlLayout
@@ -310,7 +299,6 @@ export const EuiDatePicker: FunctionComponent<EuiDatePickerProps> = ({
310299
inline && isInvalid && !disabled && !readOnly,
311300
})}
312301
iconsPosition={inline ? 'static' : undefined}
313-
style={iconAffordanceStyles} // TODO
314302
>
315303
{control}
316304
</EuiFormControlLayout>

packages/eui/src/components/form/form_control_layout/_form_control_layout.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Let the height expand as needed
66
@include euiFormControlSize($includeAlternates: true);
77

8+
// TODO: Remove this once all form controls are on Emotion/setting padding via CSS variables
89
$iconSize: map-get($euiFormControlIconSizes, 'medium');
910
$iconPadding: $euiFormControlPadding;
1011
$marginBetweenIcons: $euiFormControlPadding / 2;

packages/eui/src/components/form/form_control_layout/_num_icons.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const getIconAffordanceStyles = ({
6060
isDropdown,
6161
}: {
6262
icon?: EuiFormControlLayoutIconsProps['icon'];
63-
clear?: boolean;
63+
clear?: EuiFormControlLayoutIconsProps['clear'] | boolean;
6464
isLoading?: boolean;
6565
isInvalid?: boolean;
6666
isDropdown?: boolean;

packages/eui/src/components/form/form_control_layout/form_control_layout.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import React, {
1515
} from 'react';
1616
import classNames from 'classnames';
1717

18+
import { getIconAffordanceStyles } from './_num_icons';
1819
import {
1920
EuiFormControlLayoutIcons,
2021
EuiFormControlLayoutIconsProps,
@@ -68,6 +69,10 @@ export type EuiFormControlLayoutProps = CommonProps &
6869
export class EuiFormControlLayout extends Component<EuiFormControlLayoutProps> {
6970
static contextType = FormContext;
7071

72+
static defaultProps = {
73+
iconsPosition: 'absolute',
74+
};
75+
7176
render() {
7277
const { defaultFullWidth } = this.context as FormContextValue;
7378
const {
@@ -101,13 +106,27 @@ export class EuiFormControlLayout extends Component<EuiFormControlLayoutProps> {
101106
className
102107
);
103108

109+
const iconAffordanceStyles =
110+
iconsPosition === 'absolute' // Static icons don't need padding affordance
111+
? getIconAffordanceStyles({
112+
icon,
113+
clear,
114+
isInvalid,
115+
isLoading,
116+
isDropdown,
117+
})
118+
: undefined;
119+
104120
const prependNodes = this.renderSideNode('prepend', prepend, inputId);
105121
const appendNodes = this.renderSideNode('append', append, inputId);
106122

107123
return (
108124
<div className={classes} {...rest}>
109125
{prependNodes}
110-
<div className="euiFormControlLayout__childrenWrapper">
126+
<div
127+
className="euiFormControlLayout__childrenWrapper"
128+
style={iconAffordanceStyles}
129+
>
111130
{this.renderLeftIcons()}
112131
{children}
113132
{this.renderRightIcons()}

0 commit comments

Comments
 (0)