Skip to content

Commit f50ebe4

Browse files
committed
feat(SearchInput): enable animations
1 parent b8f1dfd commit f50ebe4

9 files changed

Lines changed: 118 additions & 29 deletions

File tree

packages/react-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"tslib": "^2.8.1"
5555
},
5656
"devDependencies": {
57-
"@patternfly/patternfly": "6.3.0-prerelease.20",
57+
"@patternfly/patternfly": "6.3.0-prerelease.32",
5858
"case-anything": "^3.1.2",
5959
"css": "^3.0.0",
6060
"fs-extra": "^11.3.0"

packages/react-core/src/components/SearchInput/SearchInput.tsx

Lines changed: 87 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { TextInputGroup, TextInputGroupMain, TextInputGroupUtilities } from '../
1414
import { InputGroup, InputGroupItem } from '../InputGroup';
1515
import { Popper } from '../../helpers';
1616
import textInputGroupStyles from '@patternfly/react-styles/css/components/TextInputGroup/text-input-group';
17+
import inputGroupStyles from '@patternfly/react-styles/css/components/InputGroup/input-group';
1718

1819
/** Properties for adding search attributes to an advanced search input. These properties must
1920
* be passed in as an object within an array to the search input component's attribute property.
@@ -41,6 +42,8 @@ export interface SearchInputExpandable {
4142
onToggleExpand: (event: React.SyntheticEvent<HTMLButtonElement>, isExpanded: boolean) => void;
4243
/** An accessible label for the expandable search input toggle. */
4344
toggleAriaLabel: string;
45+
/** Flag indicating animations should be enabled when the search input expands and collapses. */
46+
hasAnimations?: boolean;
4447
}
4548

4649
/** The main search input component. */
@@ -177,7 +180,7 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
177180
const popperRef = useRef(null);
178181
const [focusAfterExpandChange, setFocusAfterExpandChange] = useState(false);
179182

180-
const { isExpanded, onToggleExpand, toggleAriaLabel } = expandableInput || {};
183+
const { isExpanded, onToggleExpand, toggleAriaLabel, hasAnimations } = expandableInput || {};
181184

182185
useEffect(() => {
183186
// this effect and the focusAfterExpandChange variable are needed to focus the input/toggle as needed when the
@@ -349,7 +352,31 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
349352
</TextInputGroup>
350353
);
351354

352-
const expandableToggle = (
355+
const expandToggleButton = (
356+
<Button
357+
variant={ButtonVariant.plain}
358+
aria-label={toggleAriaLabel}
359+
aria-expanded={isExpanded}
360+
icon={<SearchIcon />}
361+
onClick={onExpandHandler}
362+
ref={searchInputExpandableToggleRef}
363+
{...(isExpanded && { inert: '' })}
364+
/>
365+
);
366+
367+
const collapseToggleButton = (
368+
<Button
369+
variant={ButtonVariant.plain}
370+
aria-label={toggleAriaLabel}
371+
aria-expanded={isExpanded}
372+
icon={<TimesIcon />}
373+
onClick={onExpandHandler}
374+
ref={searchInputExpandableToggleRef}
375+
{...(!isExpanded && { inert: '' })}
376+
/>
377+
);
378+
379+
const singleButtonToggle = (
353380
<Button
354381
variant={ButtonVariant.plain}
355382
aria-label={toggleAriaLabel}
@@ -360,10 +387,34 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
360387
/>
361388
);
362389

363-
const buildExpandableSearchInput = ({ ...searchInputProps } = {}) => (
390+
const expandableToggle = (
391+
<>
392+
{!hasAnimations && <InputGroupItem isPlain>{singleButtonToggle}</InputGroupItem>}
393+
{hasAnimations && (
394+
<>
395+
<InputGroupItem className={inputGroupStyles.modifiers.searchExpand} isPlain>
396+
{expandToggleButton}
397+
</InputGroupItem>
398+
<InputGroupItem className={inputGroupStyles.modifiers.searchAction} isPlain>
399+
{collapseToggleButton}
400+
</InputGroupItem>
401+
</>
402+
)}
403+
</>
404+
);
405+
406+
const buildExpandableSearchInput = ({ ...searchInputProps }: any = {}) => (
364407
<InputGroup {...searchInputProps}>
365-
<InputGroupItem isFill>{buildTextInputGroup()} </InputGroupItem>
366-
<InputGroupItem isPlain>{expandableToggle}</InputGroupItem>
408+
<InputGroupItem
409+
isFill
410+
{...(hasAnimations && { className: inputGroupStyles.modifiers.searchInput })}
411+
{...(!isExpanded && {
412+
inert: ''
413+
})}
414+
>
415+
{buildTextInputGroup()}
416+
</InputGroupItem>
417+
{expandableToggle}
367418
</InputGroup>
368419
);
369420

@@ -377,9 +428,19 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
377428

378429
const buildSearchTextInputGroupWithExtraButtons = ({ ...searchInputProps } = {}) => (
379430
<InputGroup ref={triggerRef} {...searchInputProps}>
380-
<InputGroupItem isFill>{buildTextInputGroup()}</InputGroupItem>
431+
<InputGroupItem
432+
isFill
433+
{...(expandableInput && hasAnimations && { className: inputGroupStyles.modifiers.searchInput })}
434+
{...(expandableInput &&
435+
hasAnimations &&
436+
!isExpanded && {
437+
inert: ''
438+
})}
439+
>
440+
{buildTextInputGroup()}
441+
</InputGroupItem>
381442
{(attributes.length > 0 || onToggleAdvancedSearch) && (
382-
<InputGroupItem isPlain>
443+
<InputGroupItem isPlain {...(hasAnimations && { className: inputGroupStyles.modifiers.searchAction })}>
383444
<Button
384445
className={isSearchMenuOpen && 'pf-m-expanded'}
385446
variant={ButtonVariant.control}
@@ -392,7 +453,7 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
392453
</InputGroupItem>
393454
)}
394455
{!!onSearch && (
395-
<InputGroupItem>
456+
<InputGroupItem {...(hasAnimations && { className: inputGroupStyles.modifiers.searchAction })}>
396457
<Button
397458
type="submit"
398459
variant={ButtonVariant.control}
@@ -413,11 +474,15 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
413474

414475
const searchInputProps = {
415476
...props,
416-
className: className && css(className),
477+
className: css(
478+
expandableInput && hasAnimations && inputGroupStyles.modifiers.searchExpandable,
479+
expandableInput && hasAnimations && isExpanded && inputGroupStyles.modifiers.expanded,
480+
className && css(className)
481+
),
417482
innerRef: searchInputRef
418483
};
419484

420-
if (!!expandableInput && !isExpanded) {
485+
if (!!expandableInput && !isExpanded && !hasAnimations) {
421486
return (
422487
<InputGroup {...searchInputProps}>
423488
<InputGroupItem>{expandableToggle}</InputGroupItem>
@@ -452,7 +517,12 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
452517
const AdvancedSearchWithPopper = (
453518
<div className={css(className)} ref={searchInputRef} {...props}>
454519
<Popper
455-
trigger={buildSearchTextInputGroupWithExtraButtons()}
520+
trigger={buildSearchTextInputGroupWithExtraButtons({
521+
className: css(
522+
expandableInput && hasAnimations && inputGroupStyles.modifiers.searchExpandable,
523+
expandableInput && hasAnimations && isExpanded && inputGroupStyles.modifiers.expanded
524+
)
525+
})}
456526
triggerRef={triggerRef}
457527
popper={AdvancedSearch}
458528
popperRef={popperRef}
@@ -466,7 +536,12 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
466536

467537
const AdvancedSearchInline = (
468538
<div className={css(className)} ref={searchInputRef} {...props}>
469-
{buildSearchTextInputGroupWithExtraButtons()}
539+
{buildSearchTextInputGroupWithExtraButtons({
540+
className: css(
541+
expandableInput && hasAnimations && inputGroupStyles.modifiers.searchExpandable,
542+
expandableInput && hasAnimations && isExpanded && inputGroupStyles.modifiers.expanded
543+
)
544+
})}
470545
{AdvancedSearch}
471546
</div>
472547
);

packages/react-core/src/components/SearchInput/examples/SearchInput.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,53 @@ import { ExternalLinkSquareAltIcon } from '@patternfly/react-icons';
1313
### Basic
1414

1515
```ts file='./SearchInputBasic.tsx'
16+
1617
```
1718

1819
### Match with result count
1920

2021
```ts file='./SearchInputWithResultCount.tsx'
22+
2123
```
2224

2325
### Match with navigable options
2426

2527
```ts file='./SearchInputWithNavigableOptions.tsx'
28+
2629
```
2730

2831
### With submit button
2932

3033
```ts file='./SearchInputWithSubmitButton.tsx'
34+
3135
```
3236

3337
### Focus search input using ref
3438

3539
```ts file='./SearchInputFocusSearch.tsx'
40+
3641
```
3742

3843
### With expandable button
3944

45+
Animations on the expansion and collapse of the search input may be opted into by passing `hasAnimations` to the `expandableInput` object.
46+
4047
```ts file='./SearchInputWithExpandable.tsx'
48+
4149
```
4250

4351
### Advanced
4452

4553
The search input component can be used to dynamically build a one to one attribute-value advanced search.
4654
Using the `attributes` prop alongside the `advancedSearchDelimiter` will expose this functionality, as demonstrated in
47-
the following example. The search input component can also be used as a composable component and paired with a Popper
48-
or other elements to build a completely custom advanced search form. This feature is demonstrated
55+
the following example. The search input component can also be used as a composable component and paired with a Popper
56+
or other elements to build a completely custom advanced search form. This feature is demonstrated
4957
in the search input's <a href="/components/search-input/react-demos">react demos</a>.
5058

5159
The values used in the attribute-value form fields may contain spaces. The values containing spaces
5260
should be wrapped with quotes inside the summary search string in the input field. If the latter is
5361
autogenerated from the individual fields the quotes will be autoplaced.
5462

5563
```ts file='./SearchInputAdvanced.tsx'
64+
5665
```

packages/react-core/src/components/SearchInput/examples/SearchInputWithExpandable.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ export const SearchInputWithExpandable: React.FunctionComponent = () => {
2020
value={value}
2121
onChange={(_event, value) => onChange(value)}
2222
onClear={() => onChange('')}
23-
expandableInput={{ isExpanded, onToggleExpand, toggleAriaLabel: 'Expandable search input toggle' }}
23+
expandableInput={{
24+
isExpanded,
25+
onToggleExpand,
26+
toggleAriaLabel: 'Expandable search input toggle',
27+
hasAnimations: true
28+
}}
2429
/>
2530
);
2631
};

packages/react-docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"test:a11y": "patternfly-a11y --config patternfly-a11y.config"
2424
},
2525
"dependencies": {
26-
"@patternfly/patternfly": "6.3.0-prerelease.20",
26+
"@patternfly/patternfly": "6.3.0-prerelease.32",
2727
"@patternfly/react-charts": "workspace:^",
2828
"@patternfly/react-code-editor": "workspace:^",
2929
"@patternfly/react-core": "workspace:^",

packages/react-icons/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@fortawesome/free-brands-svg-icons": "^5.15.4",
3434
"@fortawesome/free-regular-svg-icons": "^5.15.4",
3535
"@fortawesome/free-solid-svg-icons": "^5.15.4",
36-
"@patternfly/patternfly": "6.3.0-prerelease.20",
36+
"@patternfly/patternfly": "6.3.0-prerelease.32",
3737
"fs-extra": "^11.3.0",
3838
"tslib": "^2.8.1"
3939
},

packages/react-styles/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"clean": "rimraf dist css"
2020
},
2121
"devDependencies": {
22-
"@patternfly/patternfly": "6.3.0-prerelease.20",
22+
"@patternfly/patternfly": "6.3.0-prerelease.32",
2323
"change-case": "^5.4.4",
2424
"fs-extra": "^11.3.0"
2525
},

packages/react-tokens/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
},
3131
"devDependencies": {
3232
"@adobe/css-tools": "^4.4.2",
33-
"@patternfly/patternfly": "6.3.0-prerelease.20",
33+
"@patternfly/patternfly": "6.3.0-prerelease.32",
3434
"fs-extra": "^11.3.0"
3535
}
3636
}

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3639,10 +3639,10 @@ __metadata:
36393639
languageName: node
36403640
linkType: hard
36413641

3642-
"@patternfly/patternfly@npm:6.3.0-prerelease.20":
3643-
version: 6.3.0-prerelease.20
3644-
resolution: "@patternfly/patternfly@npm:6.3.0-prerelease.20"
3645-
checksum: 10c0/ea6ea0bdc09fe505f07554406f03151c63eba6e66c8abd8b35a7f67bdacfa3bcf9963e20df1b4792e22ca3c8763c926dc9ab18a089288e04f922d76c3972b80f
3642+
"@patternfly/patternfly@npm:6.3.0-prerelease.32":
3643+
version: 6.3.0-prerelease.32
3644+
resolution: "@patternfly/patternfly@npm:6.3.0-prerelease.32"
3645+
checksum: 10c0/c56f1f3b244ad747d755c4d3a96f364252caa8e47387c130e10e0cdf5d26a43225a6884aa24607500a01f78d2c81962bc734737d589f2dd7a7f58817ead3fd9a
36463646
languageName: node
36473647
linkType: hard
36483648

@@ -3740,7 +3740,7 @@ __metadata:
37403740
version: 0.0.0-use.local
37413741
resolution: "@patternfly/react-core@workspace:packages/react-core"
37423742
dependencies:
3743-
"@patternfly/patternfly": "npm:6.3.0-prerelease.20"
3743+
"@patternfly/patternfly": "npm:6.3.0-prerelease.32"
37443744
"@patternfly/react-icons": "workspace:^"
37453745
"@patternfly/react-styles": "workspace:^"
37463746
"@patternfly/react-tokens": "workspace:^"
@@ -3761,7 +3761,7 @@ __metadata:
37613761
resolution: "@patternfly/react-docs@workspace:packages/react-docs"
37623762
dependencies:
37633763
"@patternfly/documentation-framework": "npm:^6.5.20"
3764-
"@patternfly/patternfly": "npm:6.3.0-prerelease.20"
3764+
"@patternfly/patternfly": "npm:6.3.0-prerelease.32"
37653765
"@patternfly/patternfly-a11y": "npm:5.1.0"
37663766
"@patternfly/react-charts": "workspace:^"
37673767
"@patternfly/react-code-editor": "workspace:^"
@@ -3801,7 +3801,7 @@ __metadata:
38013801
"@fortawesome/free-brands-svg-icons": "npm:^5.15.4"
38023802
"@fortawesome/free-regular-svg-icons": "npm:^5.15.4"
38033803
"@fortawesome/free-solid-svg-icons": "npm:^5.15.4"
3804-
"@patternfly/patternfly": "npm:6.3.0-prerelease.20"
3804+
"@patternfly/patternfly": "npm:6.3.0-prerelease.32"
38053805
fs-extra: "npm:^11.3.0"
38063806
tslib: "npm:^2.8.1"
38073807
peerDependencies:
@@ -3885,7 +3885,7 @@ __metadata:
38853885
version: 0.0.0-use.local
38863886
resolution: "@patternfly/react-styles@workspace:packages/react-styles"
38873887
dependencies:
3888-
"@patternfly/patternfly": "npm:6.3.0-prerelease.20"
3888+
"@patternfly/patternfly": "npm:6.3.0-prerelease.32"
38893889
change-case: "npm:^5.4.4"
38903890
fs-extra: "npm:^11.3.0"
38913891
languageName: unknown
@@ -3927,7 +3927,7 @@ __metadata:
39273927
resolution: "@patternfly/react-tokens@workspace:packages/react-tokens"
39283928
dependencies:
39293929
"@adobe/css-tools": "npm:^4.4.2"
3930-
"@patternfly/patternfly": "npm:6.3.0-prerelease.20"
3930+
"@patternfly/patternfly": "npm:6.3.0-prerelease.32"
39313931
fs-extra: "npm:^11.3.0"
39323932
languageName: unknown
39333933
linkType: soft

0 commit comments

Comments
 (0)