diff --git a/components/lib/dropdown/Dropdown.js b/components/lib/dropdown/Dropdown.js index 0c4617517f..de1c0c83da 100644 --- a/components/lib/dropdown/Dropdown.js +++ b/components/lib/dropdown/Dropdown.js @@ -31,6 +31,7 @@ export const Dropdown = React.memo( const virtualScrollerRef = React.useRef(null); const searchTimeout = React.useRef(null); const searchValue = React.useRef(null); + const lastSelectedOption = React.useRef(null); const isLazy = props.virtualScrollerOptions && props.virtualScrollerOptions.lazy; const hasFilter = ObjectUtils.isNotEmpty(filterState); const appendTo = props.appendTo || (context && context.appendTo) || PrimeReact.appendTo; @@ -930,7 +931,24 @@ export const Dropdown = React.memo( const getSelectedOption = () => { const index = getSelectedOptionIndex(props.options); - return index !== -1 ? (props.optionGroupLabel ? getOptionGroupChildren(props.options[index.group])[index.option] : props.options[index]) : null; + const currentOption = index !== -1 ? (props.optionGroupLabel ? getOptionGroupChildren(props.options[index.group])[index.option] : props.options[index]) : null; + + // selected value not shown if not present in options list #8510 + if (currentOption) { + lastSelectedOption.current = currentOption; + + return currentOption; + } + + if (props.value != null && lastSelectedOption.current != null) { + const key = equalityKey(); + + if (ObjectUtils.equals(props.value, getOptionValue(lastSelectedOption.current), key)) { + return lastSelectedOption.current; + } + } + + return null; }; React.useImperativeHandle(ref, () => ({ diff --git a/package-lock.json b/package-lock.json index cc6ee9870d..7d7387d536 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "chart.js": "4.5.0", "file-saver": "2.0.5", "fs-extra": "^11.3.2", - "jspdf": "3.0.2", + "jspdf": "4.0.0", "jspdf-autotable": "5.0.2", "next": "12.3.7", "path": "^0.12.7", @@ -2204,9 +2204,9 @@ } }, "node_modules/@babel/runtime": { - "version": "7.28.3", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.28.3.tgz", - "integrity": "sha512-9uIQ10o0WGdpP6GDhXcdOJPJuDgFtIDtN/9+ArJQ2NAfAmiuhTQdzkaTGR33v43GYS2UrSA0eX2pPPHoFVvpxA==", + "version": "7.29.2", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.29.2.tgz", + "integrity": "sha512-JiDShH45zKHWyGe4ZNVRrCjBz8Nh9TMmZG1kh4QTK8hCBTWBi8Da+i7s1fJw7/lYpM4ccepSNfqzZ/QvABBi5g==", "license": "MIT", "engines": { "node": ">=6.9.0" @@ -11637,12 +11637,12 @@ } }, "node_modules/jspdf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/jspdf/-/jspdf-3.0.2.tgz", - "integrity": "sha512-G0fQDJ5fAm6UW78HG6lNXyq09l0PrA1rpNY5i+ly17Zb1fMMFSmS+3lw4cnrAPGyouv2Y0ylujbY2Ieq3DSlKA==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jspdf/-/jspdf-4.0.0.tgz", + "integrity": "sha512-w12U97Z6edKd2tXDn3LzTLg7C7QLJlx0BPfM3ecjK2BckUl9/81vZ+r5gK4/3KQdhAcEZhENUxRhtgYBj75MqQ==", "license": "MIT", "dependencies": { - "@babel/runtime": "^7.26.9", + "@babel/runtime": "^7.28.4", "fast-png": "^6.2.0", "fflate": "^0.8.1" },