Skip to content

Commit 7c826eb

Browse files
committed
code review feedback
1 parent 628966f commit 7c826eb

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

components/dash-core-components/src/utils/optionRendering.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,43 @@ interface StylingProps {
1616
labelStyle?: React.CSSProperties;
1717
}
1818

19-
interface OptionProps extends StylingProps {
20-
index: number;
21-
option: DetailedOption;
22-
isSelected: boolean;
23-
onChange: (option: DetailedOption) => void;
19+
interface OptionLabelProps extends DetailedOption {
20+
index: string | number;
2421
}
2522

26-
export function OptionLabel(
27-
props: DetailedOption & {index: string | number}
28-
): JSX.Element {
23+
export const OptionLabel: React.FC<OptionLabelProps> = ({
24+
index,
25+
label,
26+
title,
27+
value,
28+
}) => {
2929
const ctx = window.dash_component_api.useDashContext();
3030
const ExternalWrapper = window.dash_component_api.ExternalWrapper;
3131

32-
if (typeof props.label === 'object') {
33-
const labels =
34-
props.label instanceof Array ? props.label : [props.label];
32+
if (typeof label === 'object') {
33+
const labels = label instanceof Array ? label : [label];
3534
return (
3635
<>
3736
{labels.map((label, i) => (
3837
<ExternalWrapper
3938
key={i}
4039
component={label}
41-
componentPath={[...ctx.componentPath, props.index, i]}
40+
componentPath={[...ctx.componentPath, index, i]}
4241
/>
4342
))}
4443
</>
4544
);
4645
}
4746

48-
const displayLabel = `${props.label ?? props.value}`;
49-
return <span title={props.title}>{displayLabel}</span>;
47+
const displayLabel = `${label ?? value}`;
48+
return <span title={title}>{displayLabel}</span>;
49+
};
50+
51+
interface OptionProps extends StylingProps {
52+
index: number;
53+
option: DetailedOption;
54+
isSelected: boolean;
55+
onChange: (option: DetailedOption) => void;
5056
}
5157

5258
export const Option: React.FC<OptionProps> = ({

components/dash-core-components/src/utils/optionTypes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import {DetailedOption, DropdownProps, OptionValue} from '../types';
33

4-
const isDropdownValue = (option: unknown): option is OptionValue => {
4+
const isOptionValue = (option: unknown): option is OptionValue => {
55
return ['string', 'number', 'boolean'].includes(typeof option);
66
};
77

@@ -17,11 +17,11 @@ export const sanitizeOptions = (
1717

1818
if (options instanceof Array) {
1919
return options.map(option => {
20-
return isDropdownValue(option)
20+
return isOptionValue(option)
2121
? {label: String(option), value: option}
2222
: option;
2323
});
2424
}
2525

26-
return options;
26+
return [];
2727
};

0 commit comments

Comments
 (0)