Skip to content
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
43 changes: 23 additions & 20 deletions demo/FormExamples.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,48 +369,51 @@ export function FormExamples() {
options={[
{
value: {
firstValue: 'Title one',
secondValue: 1,
},
label: {
title: 'Title one',
subtitle: 'subtitle one',
},
label: (
<div>
<h5>Title one</h5>
<p>Subtitle one</p>
</div>
),
},
{
value: {
firstValue: 'Title two',
secondValue: 2,
},
label: {
title: 'Title two',
subtitle: 'subtitle two',
},
label: (
<div>
<h5>Title two</h5>
<p>Subtitle two</p>
</div>
),
},
{
value: {
firstValue: 'Title three',
secondValue: 3,
},
label: {
title: 'Title three',
subtitle: 'subtitle three',
},
label: (
<div>
<h5>Title three</h5>
<p>Subtitle three</p>
</div>
),
},
]}
help="dropdown help"
placeholder="Select one value"
afterChange={() => console.log('afterChange dropdown')}
template={(label) => <div>{label}</div>}
template={(label, value) => {
return value ? (
<div>
<strong>{label.title ?? '-'}</strong>
<p className="m-0">{label.subtitle ?? '-'}</p>
</div>
) : (
label
);
}}
itemClassName="border-bottom"
childClassName="text-muted"
trackBy="title"
trackBy="secondValue"
/>

<FormGroupDropdown
Expand Down
4 changes: 2 additions & 2 deletions src/forms/FormDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const FormDropdown = ({
const toggleDropdown = useCallback(() => (isOpen ? close() : open()), [close, isOpen, open]);

useEffect(() => {
/* The logic in this effect allows the user to close the dropdown menu when they click outside of the component. */
/* The logic in this effect allows the user to close the dropdown menu when they click outside of the component. */
const pageClickEvent = (e) => {
if (dropdownRef.current !== null && !dropdownRef.current.contains(e.target)) {
if (isOpen) {
Expand Down Expand Up @@ -92,7 +92,7 @@ export const FormDropdown = ({
className={formatClasses(['input-group justify-content-between form-control h-auto', childClassName])}
onClick={toggleDropdown}
>
{selectedItem ? template(selectedItem.label) : <div className="text-muted">{placeholder}</div>}
{selectedItem ? template(selectedItem.label, selectedItem.value) : <div className="text-muted">{placeholder}</div>}
{toggleIcon(isOpen)}
</div>
</Dropdown>
Expand Down
2 changes: 1 addition & 1 deletion src/mixed/Dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function Dropdown({
className={formatClasses(['dropdown-item', isDisabled && 'disabled', itemClassName])}
onClick={safeClick(onSelect, { value, index, label })}
>
{template(label)}
{template(label, value, index)}
</a>
))}
</div>
Expand Down