Combobox display value #33451
-
ComponentCombobox Package version9.54.17 React version18.3.1 EnvironmentSystem:
OS: macOS 13.0
CPU: (8) arm64 Apple M1
Memory: 124.70 MB / 8.00 GB
Shell: 5.8.1 - /bin/zsh
Browsers:
Brave Browser: 129.1.70.123
Chrome: 131.0.6778.109
Edge: 131.0.2903.86
Safari: 16.1
npmPackages:
@aliakbarazizi/headless-datepicker: ^2.0.2 => 2.0.2
@chamaeleonidae/chmln: ^1.0.1 => 1.0.1
@faker-js/faker: ^8.2.0 => 8.4.1
@fluentui/react-components: ^9.54.17 => 9.55.1
@fluentui/react-datepicker-compat: ^0.4.53 => 0.4.53
@headlessui/react: ^1.7.17 => 1.7.19
@headlessui/tailwindcss: ^0.2.0 => 0.2.1
@reduxjs/toolkit: ^1.9.7 => 1.9.7
@tailwindcss/forms: ^0.5.6 => 0.5.9
@tailwindcss/typography: ^0.5.14 => 0.5.15
@tanstack/react-table: ^8.10.7 => 8.20.5
@types/chamaeleonidae__chmln: ^1.0.0 => 1.0.0
@types/dompurify: ^3.0.5 => 3.0.5
@types/node: 20.8.10 => 20.8.10
@types/react: 18.3.5 => 18.3.5
@types/react-beautiful-dnd: ^13.1.7 => 13.1.8
@types/react-dom: 18.2.14 => 18.2.14
@types/react-mentions: ^4.1.11 => 4.4.0
@types/react-redux: ^7.1.28 => 7.1.34
ahooks: ^3.7.8 => 3.8.1
autoprefixer: 10.4.16 => 10.4.16
chart.js: ^4.4.0 => 4.4.5
class-variance-authority: ^0.6.1 => 0.6.1
clsx: ^1.2.1 => 1.2.1
date-fns: ^2.30.0 => 2.30.0
dompurify: ^3.1.6 => 3.1.7
dotenv: ^16.3.1 => 16.4.5
eslint-config-next: 14.2.11 => 14.2.11
firebase: ^10.0.0 => 10.14.1
googleapis: ^134.0.0 => 134.0.0
lottie-react: ^2.4.0 => 2.4.0
next: 14.2.11 => 14.2.11
nuka-carousel: ^6.0.3 => 6.0.3
postcss: 8.4.31 => 8.4.31
prettier: ^3.1.1 => 3.3.3
prettier-plugin-tailwindcss: ^0.5.9 => 0.5.14
react: 18.3.1 => 18.3.1
react-beautiful-dnd: ^13.1.1 => 13.1.1
react-chartjs-2: ^5.2.0 => 5.2.0
react-dom: 18.3.1 => 18.3.1
react-google-drive-picker: ^1.2.2 => 1.2.2
react-hook-form: ^7.47.0 => 7.53.1
react-joyride: ^2.7.2 => 2.9.2
react-markdown: ^9.0.1 => 9.0.1
react-mentions: ^4.4.10 => 4.4.10
react-player: ^2.13.0 => 2.16.0
react-redux: ^8.1.3 => 8.1.3
react-responsive: ^9.0.2 => 9.0.2
react-toastify: ^9.1.3 => 9.1.3
react-tooltip: ^5.25.1 => 5.28.0
remark-emoji: ^5.0.1 => 5.0.1
sharp: ^0.33.5 => 0.33.5
tailwindcss: ^3.3.5 => 3.4.14
typescript: 5.2.2 => 5.2.2 Current BehaviorI have an array of [ id , value] . I want them to be used in a Combobox. I can't pass an array of string because my
but now i can't control the display Another issue how to control the input value for the combobox. Just see your documentation there is no mention of Expected Behaviorthere should be some way to control the text in the trigger Reproductionimport React from "react"; import { DropdownProps, makeStyles, Option, useId, Combobox } from "@fluentui/react-components"; import CustomText from "@/components/fluent/text"; const useStyles = makeStyles({ dropdown: { minWidth: "unset !important", }, truncatedText: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", fontWeight: "300", }, optionText: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", }, }); interface OptionType { id: string; value: string; icon?: React.ReactNode; } interface CustomComboBoxProps { options?: OptionType[]; onChange?: (value: OptionType | OptionType[]) => void; selectedValueStyle?: string; optionClassName?: string; listboxClassName?: string; optionProps?: Record<string, any>; multiselect?: boolean; placeholder?: string; className?: string; selectedOptions: string[] | undefined; children?: React.ReactNode; listbox?: DropdownProps["listbox"]; isSearchable?: boolean; defaultSelectedOptions?: string[]; [key: string]: any; } const CustomComboBox: React.FC = ({ options, onChange, listbox, selectedValueStyle = "", optionClassName = "", className = "", listboxClassName = "", optionProps = {}, selectedOptions = [], defaultSelectedOptions = [], multiselect = false, placeholder = "Select option(s)", children, ...props }) => { const styles = useStyles(); const dropdownId = useId("combobox"); const handleChange: DropdownProps["onOptionSelect"] = (event, data) => { if (multiselect) { const selectedObjects = data.selectedOptions.map((id) => options?.find((option: OptionType) => option?.id === id) || { id, value: id }); onChange && onChange(selectedObjects); } else { const selectedObject = options?.find((option: OptionType) => option?.id === data?.optionValue) || { id: data.optionValue as string, value: data.optionText as string, }; onChange && onChange(selectedObject); } }; const getDisplayValue = (id: string): string => { const option = options?.find?.((opt) => opt.id === id); return option ? option.value : id; }; // Convert selectedOptions (IDs) to their corresponding display values const selectedDisplayValues = selectedOptions.map(getDisplayValue); return ( <Combobox id={dropdownId} onOptionSelect={handleChange} className={ Steps to reproducegiving the code i am trying to use could you modify it so that things can be handled Are you reporting an Accessibility issue?None Suggested severityUrgent - No workaround and Products/sites are affected Products/sites affectedNo response Are you willing to submit a PR to fix?no Validations
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
HI @jimjacob29, I've converted your issue to a discussion, since this is a question about usage of Combobox. The display value can be controlled using the The If you still have questions, please include a link to a Stackblitz with the repro, rather than pasting the code directly in the question. You can get started with a Stackblitz by clicking on "Open in Stackblitz" on any of the examples on the documentation page, such as the one I linked above. Thanks! |
Beta Was this translation helpful? Give feedback.
HI @jimjacob29, I've converted your issue to a discussion, since this is a question about usage of Combobox.
The display value can be controlled using the
value
prop. You can set it even if you're also settingselectedOptions
. See this example: https://react.fluentui.dev/?path=/docs/components-combobox--docs#controlled (the second combobox in that example).The
onInput
prop is forwarded directly to theinput
element. It should work just like a normal ReactonInput
event. The example linked above also shows how to useonInput
.If you still have questions, please include a link to a Stackblitz with the repro, rather than pasting the code directly in the question. You can get started with a …