@patternfly/react-core 4.202.1 → 4.202.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.202.1",
3
+ "version": "4.202.4",
4
4
  "description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -34,9 +34,9 @@
34
34
  "generate": "node scripts/copyStyles.js"
35
35
  },
36
36
  "dependencies": {
37
- "@patternfly/react-icons": "^4.53.1",
38
- "@patternfly/react-styles": "^4.52.1",
39
- "@patternfly/react-tokens": "^4.54.1",
37
+ "@patternfly/react-icons": "^4.53.4",
38
+ "@patternfly/react-styles": "^4.52.4",
39
+ "@patternfly/react-tokens": "^4.54.4",
40
40
  "focus-trap": "6.2.2",
41
41
  "react-dropzone": "9.0.0",
42
42
  "tippy.js": "5.1.2",
@@ -60,5 +60,5 @@
60
60
  "react": "^16.8.0 || ^17.0.0",
61
61
  "react-dom": "^16.8.0 || ^17.0.0"
62
62
  },
63
- "gitHead": "fc88ddd5f942598163a34ad5a8df86215cc7a6a5"
63
+ "gitHead": "b690e1d99c3286250b85d61e543251538a86cf3f"
64
64
  }
@@ -444,11 +444,7 @@ const SecondaryDropdown = () => {
444
444
  onFocus();
445
445
  }}
446
446
  toggle={
447
- <DropdownToggle
448
- onToggle={next => setIsOpen(next)}
449
- toggleIndicator={CaretDownIcon}
450
- id="toggle-id-plain-text"
451
- >
447
+ <DropdownToggle onToggle={next => setIsOpen(next)} toggleIndicator={CaretDownIcon} id="toggle-id-plain-text">
452
448
  Dropdown
453
449
  </DropdownToggle>
454
450
  }
@@ -1489,53 +1485,95 @@ class ImageTextDropdown extends React.Component {
1489
1485
  }
1490
1486
  ```
1491
1487
 
1492
- ### Append menu document body
1488
+ ### Appending document body vs parent
1489
+
1490
+ Avoid passing in `document.body` when passing a value to the `menuAppendTo` prop on the Dropdown component, as it can cause accessibility issues. These issues can include, but are not limited to, being unable to enter the contents of the Dropdown options via assistive technologies (like keyboards or screen readers).
1491
+
1492
+ Instead append to `"parent"` to achieve the same result without sacrificing accessibility.
1493
+
1494
+ In this example, while, after making a selection, both variants retain focus on their respective Dropdown component, the options for the `document.body` variant cannot be navigated to via Voice Over.
1493
1495
 
1494
1496
  ```js
1495
1497
  import React from 'react';
1496
- import { Dropdown, DropdownToggle, DropdownItem } from '@patternfly/react-core';
1498
+ import { Dropdown, DropdownToggle, DropdownItem, Flex } from '@patternfly/react-core';
1497
1499
  import CaretDownIcon from '@patternfly/react-icons/dist/esm/icons/caret-down-icon';
1498
1500
 
1499
- class MenuOnDocumentBodyDropdown extends React.Component {
1501
+ class DropdownDocumentBodyVsParent extends React.Component {
1500
1502
  constructor(props) {
1501
1503
  super(props);
1502
1504
  this.state = {
1503
- isOpen: false
1505
+ isBodyOpen: false,
1506
+ isParentOpen: false
1504
1507
  };
1505
- this.onToggle = isOpen => {
1508
+ this.onBodyToggle = isBodyOpen => {
1506
1509
  this.setState({
1507
- isOpen
1510
+ isBodyOpen
1508
1511
  });
1509
1512
  };
1510
- this.onSelect = event => {
1513
+ this.onBodySelect = event => {
1511
1514
  this.setState({
1512
- isOpen: !this.state.isOpen
1515
+ isBodyOpen: !this.state.isBodyOpen
1513
1516
  });
1514
- this.onFocus();
1517
+ this.onBodyFocus();
1515
1518
  };
1516
- this.onFocus = () => {
1517
- const element = document.getElementById('toggle-id-menu-document-body');
1519
+ this.onBodyFocus = () => {
1520
+ const element = document.getElementById('toggle-id-document-body');
1521
+ element.focus();
1522
+ };
1523
+
1524
+ this.onParentToggle = isParentOpen => {
1525
+ this.setState({
1526
+ isParentOpen
1527
+ });
1528
+ };
1529
+ this.onParentSelect = event => {
1530
+ this.setState({
1531
+ isParentOpen: !this.state.isParentOpen
1532
+ });
1533
+ this.onParentFocus();
1534
+ };
1535
+ this.onParentFocus = () => {
1536
+ const element = document.getElementById('toggle-id-parent');
1518
1537
  element.focus();
1519
1538
  };
1520
1539
  }
1521
1540
 
1522
1541
  render() {
1523
- const { isOpen } = this.state;
1524
- const dropdownItems = [<DropdownItem key="link">1</DropdownItem>];
1542
+ const { isBodyOpen, isParentOpen } = this.state;
1543
+ const dropdownItems = [
1544
+ <DropdownItem key="link">Link</DropdownItem>,
1545
+ <DropdownItem key="action" component="button">
1546
+ Action
1547
+ </DropdownItem>,
1548
+ <DropdownItem key="disabled link" isDisabled href="www.google.com">
1549
+ Disabled link
1550
+ </DropdownItem>
1551
+ ];
1525
1552
  return (
1526
- <div style={{ height: '50px', overflow: 'hidden' }}>
1553
+ <Flex>
1527
1554
  <Dropdown
1528
- onSelect={this.onSelect}
1555
+ onSelect={this.onBodySelect}
1529
1556
  toggle={
1530
- <DropdownToggle id="toggle-id-menu-document-body" onToggle={this.onToggle} toggleIndicator={CaretDownIcon}>
1531
- Dropdown
1557
+ <DropdownToggle id="toggle-id-document-body" onToggle={this.onBodyToggle} toggleIndicator={CaretDownIcon}>
1558
+ Dropdown - Document Body
1532
1559
  </DropdownToggle>
1533
1560
  }
1534
- isOpen={isOpen}
1561
+ isOpen={isBodyOpen}
1535
1562
  dropdownItems={dropdownItems}
1536
1563
  menuAppendTo={() => document.body}
1537
1564
  />
1538
- </div>
1565
+ <Dropdown
1566
+ onSelect={this.onParentSelect}
1567
+ toggle={
1568
+ <DropdownToggle id="toggle-id-parent" onToggle={this.onParentToggle} toggleIndicator={CaretDownIcon}>
1569
+ Dropdown - Parent
1570
+ </DropdownToggle>
1571
+ }
1572
+ isOpen={isParentOpen}
1573
+ dropdownItems={dropdownItems}
1574
+ menuAppendTo="parent"
1575
+ />
1576
+ </Flex>
1539
1577
  );
1540
1578
  }
1541
1579
  }
@@ -17,7 +17,7 @@ export interface MenuToggleProps
17
17
  /** Flag indicating the toggle is full height */
18
18
  isFullHeight?: boolean;
19
19
  /** Variant styles of the menu toggle */
20
- variant?: 'default' | 'plain' | 'primary' | 'plainText';
20
+ variant?: 'default' | 'plain' | 'primary' | 'plainText' | 'secondary';
21
21
  /** Optional icon rendered inside the toggle, before the children content */
22
22
  icon?: React.ReactNode;
23
23
  /** Optional badge rendered inside the toggle, after the children content */
@@ -71,6 +71,7 @@ export class MenuToggleBase extends React.Component<MenuToggleProps> {
71
71
  styles.menuToggle,
72
72
  isExpanded && styles.modifiers.expanded,
73
73
  variant === 'primary' && styles.modifiers.primary,
74
+ variant === 'secondary' && styles.modifiers.secondary,
74
75
  (isPlain || isPlainText) && styles.modifiers.plain,
75
76
  isPlainText && styles.modifiers.text,
76
77
  isFullHeight && styles.modifiers.fullHeight,
@@ -0,0 +1,3 @@
1
+ #ws-react-c-menu-toggle-primary .pf-c-menu-toggle, #ws-react-c-menu-toggle-secondary .pf-c-menu-toggle {
2
+ vertical-align: bottom;
3
+ }
@@ -6,8 +6,11 @@ propComponents: ['MenuToggle']
6
6
  beta: true
7
7
  ---
8
8
 
9
+ import './MenuToggle.css'
10
+
9
11
  import CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';
10
12
  import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
13
+ import imgAvatar from '@patternfly/react-core/src/components/Avatar/examples/avatarImg.svg';
11
14
 
12
15
  ## Examples
13
16
 
@@ -41,17 +44,6 @@ import { MenuToggle } from '@patternfly/react-core';
41
44
 
42
45
  ```
43
46
 
44
- ### Icon
45
-
46
- ```ts
47
- import React from 'react';
48
- import { MenuToggle } from '@patternfly/react-core';
49
- import CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';
50
-
51
- <MenuToggle icon={<CogIcon />}>Icon</MenuToggle>;
52
-
53
- ```
54
-
55
47
  ### Count
56
48
 
57
49
  ```ts
@@ -84,6 +76,28 @@ import CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';
84
76
 
85
77
  ```
86
78
 
79
+ ### Secondary
80
+
81
+ ```ts
82
+ import React from 'react';
83
+ import { MenuToggle } from '@patternfly/react-core';
84
+ import CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';
85
+
86
+ <React.Fragment>
87
+ <MenuToggle variant="secondary">Collapsed</MenuToggle>{' '}
88
+ <MenuToggle variant="secondary" icon={<CogIcon />}>
89
+ Icon
90
+ </MenuToggle>{' '}
91
+ <MenuToggle variant="secondary" isExpanded>
92
+ Expanded
93
+ </MenuToggle>{' '}
94
+ <MenuToggle variant="secondary" isDisabled>
95
+ Disabled
96
+ </MenuToggle>
97
+ </React.Fragment>
98
+
99
+ ```
100
+
87
101
  ### Plain
88
102
 
89
103
  ```ts
@@ -123,6 +137,34 @@ import { MenuToggle } from '@patternfly/react-core';
123
137
  </React.Fragment>
124
138
  ```
125
139
 
140
+
141
+ ### With icon/image and text
142
+
143
+ ```ts
144
+ import React from 'react';
145
+ import { MenuToggle, Avatar } from '@patternfly/react-core';
146
+ import CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';
147
+
148
+ <React.Fragment>
149
+ <MenuToggle icon={<CogIcon />} variant="secondary">Icon</MenuToggle>{' '}
150
+ <MenuToggle icon={<CogIcon />} variant="secondary" isDisabled>Icon</MenuToggle>
151
+ </React.Fragment>
152
+ ```
153
+
154
+ ### With avatar and text
155
+
156
+ ```ts
157
+ import React from 'react';
158
+ import { MenuToggle, Avatar } from '@patternfly/react-core';
159
+ import imgAvatar from '@patternfly/react-core/src/components/Avatar/examples/avatarImg.svg';
160
+
161
+ <React.Fragment>
162
+ <MenuToggle icon={<Avatar src={imgAvatar} alt="avatar" />}>Ned Username</MenuToggle>{' '}
163
+ <MenuToggle icon={<Avatar src={imgAvatar} alt="avatar" />} isExpanded>Ned Username</MenuToggle>{' '}
164
+ <MenuToggle icon={<Avatar src={imgAvatar} alt="avatar" />} isDisabled>Ned Username</MenuToggle>
165
+ </React.Fragment>
166
+ ```
167
+
126
168
  ### Full height
127
169
 
128
170
  ```ts
@@ -2210,79 +2210,122 @@ class SingleSelectInput extends React.Component {
2210
2210
  }
2211
2211
  ```
2212
2212
 
2213
- ### Select menu document body
2213
+ ### Appending document body vs parent
2214
+
2215
+ Avoid passing in `document.body` when passing a value to the `menuAppendTo` prop on the Select component, as it can cause accessibility issues. These issues can include, but are not limited to, being unable to enter the contents of the Select options via assistive technologies (like keyboards or screen readers).
2216
+
2217
+ Instead append to `"parent"` to achieve the same result without sacrificing accessibility.
2218
+
2219
+ In this example, while, when the dropdown is opened, both Select variants handle focus management within their dropdown contents the same way, you'll notice a difference when you try pressing the Tab key after selecting an option.
2220
+
2221
+ For the `document.body` variant, the focus will be placed at the end of the page, since that is where the dropdown content is appended to in the DOM (rather than focus being placed on the second Select variant as one might expect). For the `"parent"` variant, however, the focus will be placed on the next tab-able element (the "Toggle JS code" button for the code editor in this case).
2214
2222
 
2215
2223
  ```js
2216
2224
  import React from 'react';
2217
- import { Select, SelectOption, SelectVariant } from '@patternfly/react-core';
2225
+ import { Select, SelectOption, Flex, FlexItem } from '@patternfly/react-core';
2218
2226
 
2219
- class SelectMenuDocumentBody extends React.Component {
2227
+ class SelectDocumentBodyVsParent extends React.Component {
2220
2228
  constructor(props) {
2221
2229
  super(props);
2230
+ this.bodyOptions = [
2231
+ <SelectOption key={0} value="Select a title - document body" isPlaceholder />,
2232
+ <SelectOption key={1} value="Mr" />,
2233
+ <SelectOption key={2} value="Miss" />,
2234
+ <SelectOption key={3} value="Mrs" />,
2235
+ <SelectOption key={4} value="Ms" />,
2236
+ <SelectOption key={6} value="Dr" />,
2237
+ <SelectOption key={7} value="Other" />
2238
+ ];
2239
+
2240
+ this.parentOptions = [
2241
+ <SelectOption key={0} value="Select a title - parent" isPlaceholder />,
2242
+ <SelectOption key={1} value="Mr" />,
2243
+ <SelectOption key={2} value="Miss" />,
2244
+ <SelectOption key={3} value="Mrs" />,
2245
+ <SelectOption key={4} value="Ms" />,
2246
+ <SelectOption key={6} value="Dr" />,
2247
+ <SelectOption key={7} value="Other" />
2248
+ ];
2222
2249
 
2223
2250
  this.state = {
2224
- isOpen: false,
2225
- selected: []
2251
+ isBodyOpen: false,
2252
+ isParentOpen: false,
2253
+ bodySelected: null,
2254
+ parentSelected: null
2226
2255
  };
2227
2256
 
2228
- this.onToggle = isOpen => {
2257
+ this.onBodyToggle = isBodyOpen => {
2229
2258
  this.setState({
2230
- isOpen
2259
+ isBodyOpen
2231
2260
  });
2232
2261
  };
2233
2262
 
2234
- this.onSelect = (event, selection) => {
2235
- const { selected } = this.state;
2236
- if (selected.includes(selection)) {
2237
- this.setState(
2238
- prevState => ({ selected: prevState.selected.filter(item => item !== selection) }),
2239
- () => console.log('selections: ', this.state.selected)
2240
- );
2241
- } else {
2242
- this.setState(
2243
- prevState => ({ selected: [...prevState.selected, selection] }),
2244
- () => console.log('selections: ', this.state.selected)
2245
- );
2263
+ this.onParentToggle = isParentOpen => {
2264
+ this.setState({
2265
+ isParentOpen
2266
+ });
2267
+ };
2268
+
2269
+ this.onBodySelect = (event, selection, isPlaceholder) => {
2270
+ if (isPlaceholder) this.clearSelection();
2271
+ else {
2272
+ this.setState({
2273
+ bodySelected: selection,
2274
+ isBodyOpen: false
2275
+ });
2276
+ console.log('selected on document body:', selection);
2277
+ }
2278
+ };
2279
+
2280
+ this.onParentSelect = (event, selection, isPlaceholder) => {
2281
+ if (isPlaceholder) this.clearSelection();
2282
+ else {
2283
+ this.setState({
2284
+ parentSelected: selection,
2285
+ isParentOpen: false
2286
+ });
2287
+ console.log('selected on parent:', selection);
2246
2288
  }
2247
2289
  };
2248
2290
 
2249
2291
  this.clearSelection = () => {
2250
2292
  this.setState({
2251
- selected: []
2293
+ selected: null,
2294
+ isOpen: false
2252
2295
  });
2253
2296
  };
2254
-
2255
- this.options = [
2256
- <SelectOption key={0} value="Debug" />,
2257
- <SelectOption key={1} value="Info" />,
2258
- <SelectOption key={2} value="Warn" />,
2259
- <SelectOption key={3} value="Error" />
2260
- ];
2261
2297
  }
2262
2298
 
2263
2299
  render() {
2264
- const { isOpen, selected } = this.state;
2265
- const titleId = 'checkbox-select-id-document-body';
2300
+ const { isBodyOpen, isParentOpen, bodySelected, parentSelected } = this.state;
2301
+
2266
2302
  return (
2267
- <div style={{ height: '50px', overflow: 'hidden' }}>
2268
- <span id={titleId} hidden>
2269
- Checkbox Title
2270
- </span>
2271
- <Select
2272
- variant={SelectVariant.checkbox}
2273
- aria-label="Select Input"
2274
- onToggle={this.onToggle}
2275
- onSelect={this.onSelect}
2276
- selections={selected}
2277
- isCheckboxSelectionBadgeHidden
2278
- isOpen={isOpen}
2279
- placeholderText="Filter by status"
2280
- aria-labelledby={titleId}
2281
- menuAppendTo={() => document.body}
2282
- >
2283
- {this.options}
2284
- </Select>
2285
- </div>
2303
+ <Flex space={{ default: 'spacerMd' }} direction={{ default: 'column' }}>
2304
+ <FlexItem>
2305
+ <Select
2306
+ aria-label="Select Input for Document Body"
2307
+ onToggle={this.onBodyToggle}
2308
+ onSelect={this.onBodySelect}
2309
+ selections={bodySelected}
2310
+ isOpen={isBodyOpen}
2311
+ menuAppendTo={() => document.body}
2312
+ >
2313
+ {this.bodyOptions}
2314
+ </Select>
2315
+ </FlexItem>
2316
+ <FlexItem>
2317
+ <Select
2318
+ aria-label="Select Input for Parent"
2319
+ onToggle={this.onParentToggle}
2320
+ onSelect={this.onParentSelect}
2321
+ selections={parentSelected}
2322
+ isOpen={isParentOpen}
2323
+ menuAppendTo="parent"
2324
+ >
2325
+ {this.parentOptions}
2326
+ </Select>
2327
+ </FlexItem>
2328
+ </Flex>
2286
2329
  );
2287
2330
  }
2288
2331
  }