[Select]: Set default value no work
Describe the bug
As title said the Select component set value is no work,,,,
<Select value="Orange" valueState="None" > <Option>Apple</Option> <Option>Orange</Option> </Select>
I set value is Orange but always apple as default value
Isolated Example
No response
Reproduction steps
1.Set Select Value as Orange 2.show wrong result 3. ...
Expected Behaviour
No response
Screenshots or Videos
No response
UI5 Web Components for React Version
2.5.0
UI5 Web Components Version
2.5.0
Browser
Edge
Operating System
Win11
Additional Context
No response
Relevant log output
Organization
No response
Declaration
- [x] I’m not disclosing any internal or sensitive information.
Hi @pupss89345
I wasn't able to reproduce this: https://stackblitz.com/edit/github-vdvctzza?file=src%2FApp.tsx
Please see the linked StackBlitz example and let me know if I missed something.
Hi Lukas your reproduce is the same as my code, but I don't know why your is work 🤔
Maybe is our components version is different ??
Hmm, this is strange. I've updated the example to use only 2.5.0 of both ui5-webcomponents and ui5-webcomponents-react packages and the behavior is still the same: https://stackblitz.com/edit/github-vdvctzza-dtwarrta?file=src%2FApp.tsx
Could you check which version of @ui5/webcomponents and @ui5/webcomponents-react is actually installed?
- npm:
npm list @ui5/webcomponents,npm list @ui5/webcomponents-react - yarn:
yarn why @ui5/webcomponents,yarn why @ui5/webcomponents-react
Hi Lukas
my version
Maybe I found the issue. It could be due to the way I created the React project and the UI5 components causing a conflict. I created the project using:
npx create-react-app my-app --template typescript
And now, updating React to version 19 is causing issues, so I downgraded it to version 18 by following these steps:
npm uninstall react react-domnpm install react@18 react-dom@npm install --no-audit --save @testing-library/jest-dom@^5.14.1 @testing-library/react@^13.0.0 @testing-library/user-event@^13.2.1 web-vitals@^2.1.0
Then I added:
npm install @ui5/webcomponents @ui5/webcomponents-react @ui5/webcomponents-fiori
And then Select component set Value don't work. I also tested the following Vite version, which works fine with your code:
npx degit SAP/ui5-webcomponents-react/templates/vite-ts#main my-project
I've tested the behavior and can confirm that it occurs when using create-react-app. Please note that the create-react-app project is not maintained anymore and is therefore not recommended to be used anymore.
Since the Select component is a web component developed by the ui5-webcomponents team, I'm going to forward this issue to their repo.
Hi Colleagues,
when using create-react-app (not maintained anymore) to set up a React application, the value property of the Select component is not working as intended. This behavior does not occur when bootstrapped with Vite or Next.js for example.
I've created an example which you can check out by forking this repo.
Reproduction steps
- Fork https://github.com/Lukas742/ui5wcr-cra
- checkout branch
issue/6800-select - install modules:
npm i - run dev server:
npm run dev - See that both Selects show "Apple" instead of "Orange" initially
@ilhan007
I'm currently working on a Vue project that uses the ui5-webcomponents. I'm having a similar issue where settings the Select value doesn't seem to work.
Im my case, the problem is that Vue seems to set the value property before the Select element is appended to the DOM, so the check will always fail in this line:
https://github.com/SAP/ui5-webcomponents/blob/c365aa30b5abab1fda5fc109d74ab27a676badae/packages/main/src/Select.ts#L454
Here, the code is trying to grab the Option's value by using option.getAttribute("value"), but at this point it will just return null, since the element wasn't appended yet (or at least that's how I understand it). If we use option.value, the correct value is then returned.
I patched the Select.js file locally to also check for option.value and that fixed the problem for me.
I see that on your PR this part of the code is still present:
https://github.com/SAP/ui5-webcomponents/pull/10904/files#diff-ca8c2caa2253733276a187c5e6795b67837cc11731b5fa3bec32181db1d182dfR468
Would it be possible to update it to also get the Option's value through option.value ?
:tada: This issue has been resolved in version v2.9.0-rc.3 :tada:
The release is available on v2.9.0-rc.3
Your semantic-release bot :package::rocket: