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

Fix #5308: Dropdown icon pass overlay visible state #5309

Merged
merged 2 commits into from
Nov 14, 2023
Merged
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
25 changes: 22 additions & 3 deletions components/doc/dropdown/templatedoc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useState } from 'react';
import { Dropdown } from '../../lib/dropdown/Dropdown';
import { ChevronDownIcon } from '../../lib/icons/chevrondown';
import { ChevronRightIcon } from '../../lib/icons/chevronright';
import { DocSectionCode } from '../common/docsectioncode';
import { DocSectionText } from '../common/docsectiontext';

Expand Down Expand Up @@ -57,11 +59,17 @@ export function TemplateDoc(props) {
const code = {
basic: `
<Dropdown value={selectedCountry} onChange={(e) => setSelectedCountry(e.value)} options={countries} optionLabel="name" placeholder="Select a Country"
valueTemplate={selectedCountryTemplate} itemTemplate={countryOptionTemplate} className="w-full md:w-14rem" panelFooterTemplate={panelFooterTemplate} />
valueTemplate={selectedCountryTemplate} itemTemplate={countryOptionTemplate} className="w-full md:w-14rem" panelFooterTemplate={panelFooterTemplate}
dropdownIcon={(opts) => {
return opts.iconProps['data-pr-overlay-visible'] ? <ChevronRightIcon {...opts.iconProps} /> : <ChevronDownIcon {...opts.iconProps} />;
}}
/>
`,
javascript: `
import React, { useState } from "react";
import { Dropdown } from 'primereact/dropdown';
import { ChevronDownIcon } from 'primereact/icons/chevrondown';
import { ChevronRightIcon } from 'primereact/icons/chevronright';
export default function TemplateDemo() {
const [selectedCountry, setSelectedCountry] = useState(null);
Expand Down Expand Up @@ -117,14 +125,19 @@ export default function TemplateDemo() {
return (
<div className="card flex justify-content-center">
<Dropdown value={selectedCountry} onChange={(e) => setSelectedCountry(e.value)} options={countries} optionLabel="name" placeholder="Select a Country"
valueTemplate={selectedCountryTemplate} itemTemplate={countryOptionTemplate} className="w-full md:w-14rem" panelFooterTemplate={panelFooterTemplate} />
valueTemplate={selectedCountryTemplate} itemTemplate={countryOptionTemplate} className="w-full md:w-14rem" panelFooterTemplate={panelFooterTemplate}
dropdownIcon={(opts) => {
return opts.iconProps['data-pr-overlay-visible'] ? <ChevronRightIcon {...opts.iconProps} /> : <ChevronDownIcon {...opts.iconProps} />;
}}/>
</div>
)
}
`,
typescript: `
import React, { useState } from "react";
import { Dropdown, DropdownChangeEvent } from 'primereact/dropdown';
import { CheckIcon } from 'primereact/icons/check';
import { StarIcon } from 'primereact/icons/star';
interface Country {
name: string;
Expand Down Expand Up @@ -185,7 +198,10 @@ export default function TemplateDemo() {
return (
<div className="card flex justify-content-center">
<Dropdown value={selectedCountry} onChange={(e: DropdownChangeEvent) => setSelectedCountry(e.value)} options={countries} optionLabel="name" placeholder="Select a Country"
valueTemplate={selectedCountryTemplate} itemTemplate={countryOptionTemplate} className="w-full md:w-14rem" panelFooterTemplate={panelFooterTemplate} />
valueTemplate={selectedCountryTemplate} itemTemplate={countryOptionTemplate} className="w-full md:w-14rem" panelFooterTemplate={panelFooterTemplate}
dropdownIcon={(opts) => {
return opts.iconProps['data-pr-overlay-visible'] ? <ChevronRightIcon {...opts.iconProps} /> : <ChevronDownIcon {...opts.iconProps} />;
}}/>/>
</div>
)
}
Expand All @@ -210,6 +226,9 @@ export default function TemplateDemo() {
itemTemplate={countryOptionTemplate}
panelFooterTemplate={panelFooterTemplate}
className="w-full md:w-14rem"
dropdownIcon={(opts) => {
return opts.iconProps['data-pr-overlay-visible'] ? <ChevronRightIcon {...opts.iconProps} /> : <ChevronDownIcon {...opts.iconProps} />;
}}
/>
</div>
<DocSectionCode code={code} />
Expand Down
3 changes: 2 additions & 1 deletion components/lib/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,8 @@ export const Dropdown = React.memo(
const createDropdownIcon = () => {
const dropdownIconProps = mergeProps(
{
className: cx('dropdownIcon')
className: cx('dropdownIcon'),
'data-pr-overlay-visible': overlayVisibleState
},
ptm('dropdownIcon')
);
Expand Down
Loading