Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3739] Use custom DownChevron and CrossIcon when supplied #3959

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/violet-fireants-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-select': minor
---

Use custom DownChevron and CrossIcon when supplied
6 changes: 4 additions & 2 deletions packages/react-select/src/components/MultiValue.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @flow
/** @jsx jsx */
import { type Node } from 'react';
import { useMemo, type Node } from 'react';
import { jsx, ClassNames } from '@emotion/core';
import { CrossIcon } from './indicators';
import type { CommonProps } from '../types';
import { defaultComponents } from './index';

export type MultiValueProps = CommonProps & {
children: Node,
Expand Down Expand Up @@ -88,7 +88,9 @@ export type MultiValueRemoveProps = {
export function MultiValueRemove({
children,
innerProps,
selectProps: { components = {} },
}: MultiValueRemoveProps) {
const CrossIcon = useMemo(() => defaultComponents({ components }).CrossIcon, [components]);
Copy link
Collaborator

@Methuselah96 Methuselah96 Jan 16, 2021

Choose a reason for hiding this comment

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

Instead of calling defaultComponents here (and the other two places), can we instead pass down the components like we do for MultiValue here.

return <div {...innerProps}>{children || <CrossIcon size={14} />}</div>;
}

Expand Down
13 changes: 8 additions & 5 deletions packages/react-select/src/components/indicators.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// @flow
/** @jsx jsx */
import { type Node } from 'react';
import { useMemo, type Node } from 'react';
import { jsx, keyframes } from '@emotion/core';

import type { CommonProps, Theme } from '../types';
import { defaultComponents } from './index';

// ==============================
// Dropdown & Clear Icons
Expand Down Expand Up @@ -73,7 +74,8 @@ const baseCSS = ({

export const dropdownIndicatorCSS = baseCSS;
export const DropdownIndicator = (props: IndicatorProps) => {
const { children, className, cx, getStyles, innerProps } = props;
const { children, className, cx, getStyles, innerProps, selectProps: { components = {} } } = props;
const DownChevronComponent = useMemo(() => defaultComponents({ components }).DownChevron, [components]);
return (
<div
{...innerProps}
Expand All @@ -86,14 +88,15 @@ export const DropdownIndicator = (props: IndicatorProps) => {
className
)}
>
{children || <DownChevron />}
{children || <DownChevronComponent />}
</div>
);
};

export const clearIndicatorCSS = baseCSS;
export const ClearIndicator = (props: IndicatorProps) => {
const { children, className, cx, getStyles, innerProps } = props;
const { children, className, cx, getStyles, innerProps, selectProps: { components = {} } } = props;
const CrossIconComponent = useMemo(() => defaultComponents({ components }).CrossIcon, [components]);
return (
<div
{...innerProps}
Expand All @@ -106,7 +109,7 @@ export const ClearIndicator = (props: IndicatorProps) => {
className
)}
>
{children || <CrossIcon />}
{children || <CrossIconComponent />}
</div>
);
};
Expand Down