ui5-webcomponents icon indicating copy to clipboard operation
ui5-webcomponents copied to clipboard

[Select]: Set default value no work

Open pupss89345 opened this issue 1 year ago • 8 comments

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.

pupss89345 avatar Jan 09 '25 07:01 pupss89345

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.

Lukas742 avatar Jan 09 '25 10:01 Lukas742

Hi Lukas your reproduce is the same as my code, but I don't know why your is work 🤔

Image

Maybe is our components version is different ?? Image

pupss89345 avatar Jan 09 '25 10:01 pupss89345

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

Lukas742 avatar Jan 09 '25 12:01 Lukas742

Hi Lukas my version Image

pupss89345 avatar Jan 10 '25 01:01 pupss89345

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:

  1. npm uninstall react react-dom
  2. npm install react@18 react-dom@
  3. 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

pupss89345 avatar Jan 10 '25 04:01 pupss89345

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

  1. Fork https://github.com/Lukas742/ui5wcr-cra
  2. checkout branch issue/6800-select
  3. install modules: npm i
  4. run dev server: npm run dev
  5. See that both Selects show "Apple" instead of "Orange" initially

Lukas742 avatar Jan 13 '25 14:01 Lukas742

@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 ?

vonBrax avatar Mar 02 '25 08:03 vonBrax

: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:

ui5-webcomponents-bot avatar Apr 03 '25 08:04 ui5-webcomponents-bot