Skip to content

Commit 225eb8c

Browse files
committed
Reworked with new prop; adjusted css concatenation tool
1 parent a1812de commit 225eb8c

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

packages/react-core/src/components/Dropdown/DropdownItem.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface DropdownItemProps extends InternalDropdownItemProps {
1212
/** Indicates which component will be used as dropdown item */
1313
component?: React.ReactNode;
1414
/** Variant of the item. The 'icon' variant should use DropdownItemIcon to wrap contained icons or images. */
15-
variant?: 'item' | 'icon' | 'routerLink';
15+
variant?: 'item' | 'icon';
1616
/** Render dropdown item as disabled option */
1717
isDisabled?: boolean;
1818
/** Forces display of the hover state of the element */
@@ -27,6 +27,8 @@ export interface DropdownItemProps extends InternalDropdownItemProps {
2727
additionalChild?: React.ReactNode;
2828
/** Custom item rendering that receives the DropdownContext */
2929
customChild?: React.ReactNode;
30+
/** Flag indicating if the dropdown item is a router link */
31+
isRouterLink?: boolean;
3032
}
3133

3234
export const DropdownItem: React.FunctionComponent<DropdownItemProps> = ({

packages/react-core/src/components/Dropdown/InternalDropdownItem.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import classNames from 'classnames';
32
import { css } from '@patternfly/react-styles';
43
import { DropdownContext } from './dropdownConstants';
54
import { KEYHANDLER_DIRECTION } from '../../helpers/constants';
@@ -16,7 +15,7 @@ export interface InternalDropdownItemProps extends React.HTMLProps<HTMLAnchorEle
1615
/** Indicates which component will be used as dropdown item */
1716
component?: React.ReactNode | string;
1817
/** Variant of the item. The 'icon' variant should use DropdownItemIcon to wrap contained icons or images. */
19-
variant?: 'item' | 'icon' | 'routerLink';
18+
variant?: 'item' | 'icon';
2019
/** Role for the item */
2120
role?: string;
2221
/** Render dropdown item as disabled option */
@@ -46,6 +45,8 @@ export interface InternalDropdownItemProps extends React.HTMLProps<HTMLAnchorEle
4645
customChild?: React.ReactNode;
4746
/** Flag indicating if hitting enter on an item also triggers an arrow down key press */
4847
enterTriggersArrowDown?: boolean;
48+
/** Flag indicating if the item is a router link */
49+
isRouterLink?: boolean;
4950
}
5051

5152
export class InternalDropdownItem extends React.Component<InternalDropdownItemProps> {
@@ -135,7 +136,7 @@ export class InternalDropdownItem extends React.Component<InternalDropdownItemPr
135136
) {
136137
return React.Children.map(children as React.ReactElement<any>, child =>
137138
React.cloneElement(child, {
138-
className: classNames(child.props.className, itemClass),
139+
className: css(child.props.className, itemClass),
139140
ref,
140141
id,
141142
...additionalProps
@@ -165,13 +166,14 @@ export class InternalDropdownItem extends React.Component<InternalDropdownItemPr
165166
additionalChild,
166167
customChild,
167168
enterTriggersArrowDown,
169+
isRouterLink,
168170
...additionalProps
169171
} = this.props;
170172
/* eslint-enable @typescript-eslint/no-unused-vars */
171173
const Component = component as any;
172174
let isComponentReactElement = false;
173175
let classes: string;
174-
if (Component === 'a' || variant === 'routerLink') {
176+
if (Component === 'a' || isRouterLink) {
175177
additionalProps['aria-disabled'] = isDisabled;
176178
additionalProps.tabIndex = isDisabled ? -1 : additionalProps.tabIndex;
177179
} else if (Component === 'button') {
@@ -225,7 +227,7 @@ export class InternalDropdownItem extends React.Component<InternalDropdownItemPr
225227
...additionalProps,
226228
className: css(classes, itemClass, variant === 'icon' && styles.modifiers.icon)
227229
})
228-
) : variant === 'routerLink' ? (
230+
) : isRouterLink ? (
229231
this.extendChildClass(children, itemClass, this.ref, id, { ...additionalProps })
230232
) : (
231233
<Component

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ class RouterDropdown extends React.Component {
11471147
render() {
11481148
const { isOpen } = this.state;
11491149
const dropdownItems = [
1150-
<DropdownItem key="routerlink" variant="routerLink">
1150+
<DropdownItem key="routerlink" isRouterLink>
11511151
<Link to="/">Link</Link>
11521152
</DropdownItem>
11531153
];

0 commit comments

Comments
 (0)