-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(module:select): value no longer reset on datasource set #1906
fix(module:select): value no longer reset on datasource set #1906
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1906 +/- ##
==========================================
+ Coverage 22.51% 23.93% +1.41%
==========================================
Files 481 499 +18
Lines 31326 23414 -7912
Branches 0 129 +129
==========================================
- Hits 7053 5603 -1450
+ Misses 24273 17808 -6465
- Partials 0 3 +3
Continue to review full report at Codecov.
|
Notice that #1536 and #1719 are different. One is using DataSource approach, another one is using SelectOption approach. (I asked @ElderJames to reopen #1536, which is not actually solved by #1720) Please make sure you can solve both. |
I think there is indeed a bug when DataSource changes, as I mentioned in #1886 However, I can't see anything wrong with #1905. You are using both |
I guess the difference is, the code in property setter is using As I mentioned, the calling order of property setters is not consistent. I still think the code should be written in |
The issue was indeed with the fact that value was reset even during initialization (or rather during Your suggestion for loading the model after the delayed task would not work in my use case, because my real model has more than 2 select components. I tried. I would have to reload the model after every task or use other set of variables. Regardless, in my opinion it is not intuitive and should be fixed. Anyway, please have a look at my latest commit. I also fixed DataSource change detection - now it also detects adding/removing (which is also reflected in the test changes & docs). I also checked the issue you mentioned in the docs - it seems to me that antD has exactly the same behavior... @ElderJames can you please remove #1536 from the list of issues this PR should solve? I incorrectly added it there and my privileges do not allow me to remove it by myself. |
I can't remove it directly either, but modifying the content of the pull request does. Maybe this is a new mechanism in GitHub. |
before you reply, I tried to avoid the first call to But when I try to solve the issue I mentioned above together(by call On ValueChanged when DataSource changes, I still avoid the first call in this case), things went wrong(the select components display empty selection). Can you try to solve this issue(value not reset to null when DataSource changes) together? |
Your use case makes sense and I also have some use case like that(however, I only have two Select in the same time and I get the model after the select DataSource). In fact, I have another idea. I think we should |
@anranruye I have mixed feelings about your proposal. It seems to me a bit inconsistent. Your suggestion is to:
What I do not like is the idea that a ui library takes a decision that should be left to the developer. Instead, I would actually advocate for additional parameter (an enum) that would allow the consumers to choose:
Or we never change (regardless) and tell the people to actually make their adjustment in |
@anddrzejb I think you are right, and your suggestions are both not bad choices(In fact, I am doing something like that). But let me explain why my idea seems a bit inconsistent. Select options are hard-coded at the client side. "1","2","3" are available. At the beginning, this works well. But as time goes on, the business develops, "4" and "5" are also valid values. Then some clients update, some clients not. When edit an item on a not updated client, we may get model value "4" from the server, but it is not in the data source("1", "2", "3"). Here we should decide to remain the value "4" or set the model value to null. I think still using "4" as the value is better, and for other situations where the model value(especially when the model is already in db) has a conflict with the select options, we should respect the model first. Another situation is the typical province - city cooperating I showed above. Consider we have "A" province with its two cities "A1" and A2, and B province with B1 and B2. City field is not required. If we select A-A1 first, then change to I like the idea that we never change, just let the user to make their own decision. But there are also some developers who are not against that we implement the most common situations. If we want to do this, then we need to consider the situations I mentioned above. |
Maybe we can follow these rules to cover the most common usage:
|
components/select/Select.razor.cs
Outdated
_dataSourceHasChanged = !value.SequenceEqual(_datasource) | ||
|| (_optionsHasInitialized && SelectOptionItems.Count != _datasource.Count()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can rely on the item count, and SelectOptionItems
also contains added tags?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot about the tags. Indeed it does, but it can be simply fixed by subtracting what we have in AddedTags
.
Count gives a basic check over the basic add/remove. It obviously won't work when a consumer adds & remove the same number of items from the DataSource
. From what I can see, currently the whole sequence comparison in DataSource
setter is useless anyway. We could just replace it with reference equality check and I think it would work the same (except probably faster).
But, we should probably keep the SequenceEqual
check but not to check it against _dataSource
but against a deep copy of the _dataSource
. I think then we could safely rely on the change detection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I think shallow copy should be good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My tests revealed that shallow copy wont cover all scenarios (given the DataSource
is an IEnumerable<Persons>
):
//will NOT detect
_persons[2].Name = newValue;
...
//will detect
_persons[2] = new Person { Id = 3, Name = "new Person()" };
...
//will detect
_persons.Remove(_persons.Last());
_persons.Add(new Person { Id = 3, Name = "removed and added" });
But we cannot really make a deep copy ourselves (possible issues: cycle object graph, references to external objects, events). So, to cover all scenarios, the only other way I can think of is to allow the consumers to pass their own IEqualityComparer
we could use in SequenceEqual()
method during DataSource
change detection - I would think these are going to be the advanced scenarios, but still available to the developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we are breaking this use-case: https://ant-design-blazor.gitee.io/zh-CN/components/select#components-select-demo-TrackItemChanges. Now a custom IEqualityComparer is necessary to track item changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I will have a look.
I also experimented with IEqualityComparer
but I think it won't really help us here, because in case of changes to an item of the DataSource
we still are making changes to the same object. So the comparer compares an object to itself. Now I start to think that we should expose our own interface/base class for DataSource
that will have a Clone
virtual method, which will do a shallow copy by default but with ability to overload it, so the consumers can create a deep copy implementation. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just call CreateDeleteSelectOptions
when IgnoreItemChanges
is false. Then shallow copy should be enough.
I guess here we should as @ElderJames for his opinion. To be honest I think I prefer my last proposal - shift the responsibility to the consumer, do not force the behavior on the consumer. So basically, follow your proposal in 1 & 3. Which in turn would also mean that we apply same logic across the board - we don't change in 2 either. |
I think you are right. We should apply same logic for all situations and that will make everything simple. If we decide to do this, then there comes an issue: how should we use |
@@ -84,33 +86,29 @@ public IEnumerable<TItem> DataSource | |||
SelectedOptionItems.Clear(); | |||
|
|||
Value = default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should change the value inside DataSource property. As I mentioned, the order to set Value
and DataSource
depends on user hand-writing. And this is actually unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If our proposal of removing value changes on DataSource
changes gets accepted, then this will most likely be removed from the setter.
@ElderJames What do you think about our changes proposal to the value? I do not want to start doing something that you might possibly reject later on. @anranruye Regarding default behavior - I believe that default value should kick in only during initialization or when clear button is clicked. If we keep the value even if it does not exist in |
I do know that DefaultValue/DefaultActiveFirstOption is used only once during initialization. That's the problem. I think people who use DefaultActiveFirstOption want to also see the first option is selected after DataSource changes(and the previous value is no longer valid). But this break the rule that we don't change the Value. To be honest, I don't like DefaultValue/DefaultActiveFirstOption at all(and I will never use them). If we want the users to take care the Value which they want, as we discussed, then they should manully set their expected value to |
I wholeheartedly agree with you. |
Though our docs says that, it is not true.
Basiclly I agree. And I noticed that currently By the way, @ElderJames agrees with us. We should change the value only when the users select an option or click clear button. |
@anranruye , @ElderJames My latest commit 1a67ca3 this time actually fixes #1536. Changes in the commit:
Edit: |
Yes, we should make
I don't like Inconsistency, either.
I think so.
That's the problem. Again, I want to emphasize, "clear" is "clear", it's not "reset" or anything else. for Input/InputNumber/TextArea, it's ok to set the value to The case is, C# has a different type system with Js. Js variables are always nullable. Js ui technologies don't have this issue, but here we have. My suggestion is to forbid "clear" for not nullable types.
Yes, I think we should break this for non-nullable types. My answer is to forbid "clear" for not nullable types. Instead, as I mentioned above, we can display a independent reset button. @ElderJames doesn't decide yet. If you agree, maybe he will agree too. |
I think we agree. What I would add is a compiler warning when non-nullable type is used that would contain a link to detailed explanation of the problem to the docs. |
hasChanged = !value.SequenceEqual(_datasource); | ||
_dataSourceHasChanged = !value.SequenceEqual(_dataSourceShallowCopy, DataSourceEqualityComparer); | ||
} | ||
|
||
if (hasChanged) | ||
if (_dataSourceHasChanged) | ||
{ | ||
OnDataSourceChanged?.Invoke(); | ||
|
||
_datasource = value; | ||
if (IsTItemPrimitive) | ||
{ | ||
_dataSourceShallowCopy = _datasource.ToList(); | ||
} | ||
else | ||
{ | ||
var cloneMethod = GetDataSourceItemCloneMethod(); | ||
_dataSourceShallowCopy = _datasource.Select(x => (TItem)cloneMethod.Invoke(x, null)).ToList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When use default DataSourceEqualityComparer and TItem is not primitive, _dataSourceHasChanged is always true and OnDataSourceChanged will be triggered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check commit af8d541 - I added internal DateSourceEqualityComparer
that is comparing only values of label & value properties of the DataSource
. Also, I included a test to cover the scenario.
I agree with you. |
@ElderJames Ok. Though this will confuse the concept of "clear" and will bring inconsistency(we should always set the value to null for nullable types), it meets the actual usage habits of users. |
@anddrzejb @anranruye Thank you for the great works. |
@ElderJames @anranruye Thanks for a fruitful discussion. I hope we will manage to implement the proposed changes. |
* fix(module: form): remove `FormItem` from `Form` when it was disposed (#1901) * pref(module: table): put fixed column style into js (#1897) * pref(module: table): put fixed column style into js * fix resize listener * docs: Add building demo assets to the Readme (#1904) * feat(module: table): add `CellData` for `CellRender` (#1907) * docs: add dynamic table demo (#1908) * feat(module: table): add dynamic data demo * add scroll x * fix(module: select): value no longer reset on datasource set (#1906) * fix(module:select): value no longer reset on datasource set * fix(module:select): dataSource change detection * fix: improve datasource detection add item & set value in SelectOption * tests: scenario from issue #1207 * fix: DataSourceEqualityComparer default * docs: Fixed typo (#1915) * fix(module: input): Add stop propagation (#1917) * docs(module: select): update coordinate demo (#1914) Co-authored-by: James Yeung <shunjiey@hotmail.com> * fix(module: textarea): add rows parameter (#1920) doc: adjust to match antD tests: sizing tests * test(module: select): Add some unit tests for Select (#1891) * Add Select clear tests * Add Select DataSource to null test * Change the implement of Throw tests * Change int to int? * fix(module: button): loading icon styles (#1902) * Fix loading icon styles * Fix button render test * feat(module: InputNumber): Add inputmode for mobile keyboard (#1923) * perf: avoid memory leak issue of event listener (#1857) * perf: avoid memory leak #1834 Avoid memory leak by remove the exclusive parameter and logic in the code block on AddEventListener method in DomEventService class. The following are the components affected: components/affix/Affix.razor.cs components/anchor/Anchor.razor.cs components/carousel/Carousel.razor.cs components/core/Component/Overlay/Overlay.razor.cs components/core/Component/Overlay/OverlayTrigger.razor.cs components/core/JsInterop/DomEventService.cs components/descriptions/Descriptions.razor.cs components/dropdown/DropdownButton.cs components/grid/Row.razor.cs components/input/Input.cs components/input/TextArea.razor.cs components/layout/Sider.razor.cs components/list/ListItem.razor.cs components/select/Select.razor.cs components/select/internal/SelectContent.razor.cs components/slider/Slider.razor.cs components/table/Table.razor.cs components/tabs/Tabs.razor.cs * fix override AddEventListener method in AntDesign.TestKit project * add register/remove event listerner for exclusive use in DomEventService class * move _dotNetObjects to DomEventListerner class/service, so that users not required to maintain it in each component. * * move share/reuse dom event listerner methods to DomEventListerner class * remove method 'AddEventListener' that no longer exists in DomEventService class in AntDesign.TestKit project * * change the component referring to an IDomEventListerner interface instead of a concrete class, so that the component can be tested via a mock TestDomEventListerner. * introduce DisposeShared and Dispose method in DomEventListerner to ease user remove callback from DomEventListerner * register IDomEventListerner into DI container instead of create manually * fix FormatKey * fix FormatKey * fix tests * fix test * fix test Co-authored-by: James Yeung <shunjiey@hotmail.com> * fix(module: textarea): replace wrong event (#1927) * tests(module: textarea): include js function mock to avoid bunit exceptions (#1930) * perf(module: overlay): positioning moved to js (#1848) * fix(module:overlay): move postion calculation to js fixes #1836 * docs: TriggerBoundaryAdjustMode explanation * docs: select & datepicker got BoundaryAdjustmetMode cleanup * test: fixes optimization & cleanup * fix(module:overlay): recalculate overlay position when trigger resizes * Minor clean-up * fix(module:overlay): wait for Show to finish in Hide * fix: prevent vertical scrollbar on overlay adding * fix: extract waiting function * fix: overlay not to repostion when trigger vanishes (menu issue) * fix: scroll adjustment for position: fixed * fix: on menu mode change, keep * merge conflict fix * fix: nominal calculation reset on failed adjustment * fix: bugs * test: exclude log method from test coverage in overlay.ts * fix(module: table): It would be load twice at first time if pagesize is not 10 (#1933) * fix(module: menu): collapsed menu title can't hide while use router link (#1934) * fix(module: select): fix data source of type IEnumerable<object> (#1932) * fix(module:select): fix data source of type IEnumerable<object> * Update Select.razor.cs * Update Select.OnDataSourceChangeTests.razor Co-authored-by: James Yeung <shunjiey@hotmail.com> * feat(module: InputNumber): Add OnFocus event (#1931) * Add on textbox focus * Adjust naming Co-authored-by: James Yeung <shunjiey@hotmail.com> * fix(module: list): resposive style doesn't work (#1937) * docs: Update index.zh-CN.md (#1936) Update document ConfigProvider global configuration example code Co-authored-by: James Yeung <shunjiey@hotmail.com> * change log 0.9.4 (#1938) * chore: test cs project to include test runner adapter (#1939) test: add general overlay disposal method mock Co-authored-by: Alan.Liu <lxyruanjian@126.com> Co-authored-by: James Yeung <shunjiey@hotmail.com> Co-authored-by: rabberbock <rabberbock@gmail.com> Co-authored-by: Andrzej Bakun <anddrzejb@poczta.fm> Co-authored-by: Chandan Rauniyar <chandankkrr@gmail.com> Co-authored-by: Luke Parker [SSW] <10430890+Hona@users.noreply.github.com> Co-authored-by: SmallY <45689960+iamSmallY@users.noreply.github.com> Co-authored-by: Maksim <maksalmak@gmail.com> Co-authored-by: Tony Yip <tonyyip1969@gmail.com> Co-authored-by: SmRiley <45205313+SmRiley@users.noreply.github.com>
* fix(module:select): value no longer reset on datasource set * fix(module:select): dataSource change detection * fix: improve datasource detection add item & set value in SelectOption * tests: scenario from issue #1207 * fix: DataSourceEqualityComparer default
* fix(module: form): remove `FormItem` from `Form` when it was disposed (#1901) * pref(module: table): put fixed column style into js (#1897) * pref(module: table): put fixed column style into js * fix resize listener * docs: Add building demo assets to the Readme (#1904) * feat(module: table): add `CellData` for `CellRender` (#1907) * docs: add dynamic table demo (#1908) * feat(module: table): add dynamic data demo * add scroll x * fix(module: select): value no longer reset on datasource set (#1906) * fix(module:select): value no longer reset on datasource set * fix(module:select): dataSource change detection * fix: improve datasource detection add item & set value in SelectOption * tests: scenario from issue #1207 * fix: DataSourceEqualityComparer default * docs: Fixed typo (#1915) * fix(module: input): Add stop propagation (#1917) * docs(module: select): update coordinate demo (#1914) Co-authored-by: James Yeung <shunjiey@hotmail.com> * fix(module: textarea): add rows parameter (#1920) doc: adjust to match antD tests: sizing tests * test(module: select): Add some unit tests for Select (#1891) * Add Select clear tests * Add Select DataSource to null test * Change the implement of Throw tests * Change int to int? * fix(module: button): loading icon styles (#1902) * Fix loading icon styles * Fix button render test * feat(module: InputNumber): Add inputmode for mobile keyboard (#1923) * perf: avoid memory leak issue of event listener (#1857) * perf: avoid memory leak #1834 Avoid memory leak by remove the exclusive parameter and logic in the code block on AddEventListener method in DomEventService class. The following are the components affected: components/affix/Affix.razor.cs components/anchor/Anchor.razor.cs components/carousel/Carousel.razor.cs components/core/Component/Overlay/Overlay.razor.cs components/core/Component/Overlay/OverlayTrigger.razor.cs components/core/JsInterop/DomEventService.cs components/descriptions/Descriptions.razor.cs components/dropdown/DropdownButton.cs components/grid/Row.razor.cs components/input/Input.cs components/input/TextArea.razor.cs components/layout/Sider.razor.cs components/list/ListItem.razor.cs components/select/Select.razor.cs components/select/internal/SelectContent.razor.cs components/slider/Slider.razor.cs components/table/Table.razor.cs components/tabs/Tabs.razor.cs * fix override AddEventListener method in AntDesign.TestKit project * add register/remove event listerner for exclusive use in DomEventService class * move _dotNetObjects to DomEventListerner class/service, so that users not required to maintain it in each component. * * move share/reuse dom event listerner methods to DomEventListerner class * remove method 'AddEventListener' that no longer exists in DomEventService class in AntDesign.TestKit project * * change the component referring to an IDomEventListerner interface instead of a concrete class, so that the component can be tested via a mock TestDomEventListerner. * introduce DisposeShared and Dispose method in DomEventListerner to ease user remove callback from DomEventListerner * register IDomEventListerner into DI container instead of create manually * fix FormatKey * fix FormatKey * fix tests * fix test * fix test Co-authored-by: James Yeung <shunjiey@hotmail.com> * fix(module: textarea): replace wrong event (#1927) * tests(module: textarea): include js function mock to avoid bunit exceptions (#1930) * perf(module: overlay): positioning moved to js (#1848) * fix(module:overlay): move postion calculation to js fixes #1836 * docs: TriggerBoundaryAdjustMode explanation * docs: select & datepicker got BoundaryAdjustmetMode cleanup * test: fixes optimization & cleanup * fix(module:overlay): recalculate overlay position when trigger resizes * Minor clean-up * fix(module:overlay): wait for Show to finish in Hide * fix: prevent vertical scrollbar on overlay adding * fix: extract waiting function * fix: overlay not to repostion when trigger vanishes (menu issue) * fix: scroll adjustment for position: fixed * fix: on menu mode change, keep * merge conflict fix * fix: nominal calculation reset on failed adjustment * fix: bugs * test: exclude log method from test coverage in overlay.ts * fix(module: table): It would be load twice at first time if pagesize is not 10 (#1933) * fix(module: menu): collapsed menu title can't hide while use router link (#1934) * fix(module: select): fix data source of type IEnumerable<object> (#1932) * fix(module:select): fix data source of type IEnumerable<object> * Update Select.razor.cs * Update Select.OnDataSourceChangeTests.razor Co-authored-by: James Yeung <shunjiey@hotmail.com> * feat(module: InputNumber): Add OnFocus event (#1931) * Add on textbox focus * Adjust naming Co-authored-by: James Yeung <shunjiey@hotmail.com> * fix(module: list): resposive style doesn't work (#1937) * docs: Update index.zh-CN.md (#1936) Update document ConfigProvider global configuration example code Co-authored-by: James Yeung <shunjiey@hotmail.com> * change log 0.9.4 (#1938) * chore: test cs project to include test runner adapter (#1939) test: add general overlay disposal method mock Co-authored-by: Alan.Liu <lxyruanjian@126.com> Co-authored-by: James Yeung <shunjiey@hotmail.com> Co-authored-by: rabberbock <rabberbock@gmail.com> Co-authored-by: Andrzej Bakun <anddrzejb@poczta.fm> Co-authored-by: Chandan Rauniyar <chandankkrr@gmail.com> Co-authored-by: Luke Parker [SSW] <10430890+Hona@users.noreply.github.com> Co-authored-by: SmallY <45689960+iamSmallY@users.noreply.github.com> Co-authored-by: Maksim <maksalmak@gmail.com> Co-authored-by: Tony Yip <tonyyip1969@gmail.com> Co-authored-by: SmRiley <45205313+SmRiley@users.noreply.github.com>
* fix(module:select): value no longer reset on datasource set * fix(module:select): dataSource change detection * fix: improve datasource detection add item & set value in SelectOption * tests: scenario from issue #1207 * fix: DataSourceEqualityComparer default
* fix(module: form): remove `FormItem` from `Form` when it was disposed (#1901) * pref(module: table): put fixed column style into js (#1897) * pref(module: table): put fixed column style into js * fix resize listener * docs: Add building demo assets to the Readme (#1904) * feat(module: table): add `CellData` for `CellRender` (#1907) * docs: add dynamic table demo (#1908) * feat(module: table): add dynamic data demo * add scroll x * fix(module: select): value no longer reset on datasource set (#1906) * fix(module:select): value no longer reset on datasource set * fix(module:select): dataSource change detection * fix: improve datasource detection add item & set value in SelectOption * tests: scenario from issue #1207 * fix: DataSourceEqualityComparer default * docs: Fixed typo (#1915) * fix(module: input): Add stop propagation (#1917) * docs(module: select): update coordinate demo (#1914) Co-authored-by: James Yeung <shunjiey@hotmail.com> * fix(module: textarea): add rows parameter (#1920) doc: adjust to match antD tests: sizing tests * test(module: select): Add some unit tests for Select (#1891) * Add Select clear tests * Add Select DataSource to null test * Change the implement of Throw tests * Change int to int? * fix(module: button): loading icon styles (#1902) * Fix loading icon styles * Fix button render test * feat(module: InputNumber): Add inputmode for mobile keyboard (#1923) * perf: avoid memory leak issue of event listener (#1857) * perf: avoid memory leak #1834 Avoid memory leak by remove the exclusive parameter and logic in the code block on AddEventListener method in DomEventService class. The following are the components affected: components/affix/Affix.razor.cs components/anchor/Anchor.razor.cs components/carousel/Carousel.razor.cs components/core/Component/Overlay/Overlay.razor.cs components/core/Component/Overlay/OverlayTrigger.razor.cs components/core/JsInterop/DomEventService.cs components/descriptions/Descriptions.razor.cs components/dropdown/DropdownButton.cs components/grid/Row.razor.cs components/input/Input.cs components/input/TextArea.razor.cs components/layout/Sider.razor.cs components/list/ListItem.razor.cs components/select/Select.razor.cs components/select/internal/SelectContent.razor.cs components/slider/Slider.razor.cs components/table/Table.razor.cs components/tabs/Tabs.razor.cs * fix override AddEventListener method in AntDesign.TestKit project * add register/remove event listerner for exclusive use in DomEventService class * move _dotNetObjects to DomEventListerner class/service, so that users not required to maintain it in each component. * * move share/reuse dom event listerner methods to DomEventListerner class * remove method 'AddEventListener' that no longer exists in DomEventService class in AntDesign.TestKit project * * change the component referring to an IDomEventListerner interface instead of a concrete class, so that the component can be tested via a mock TestDomEventListerner. * introduce DisposeShared and Dispose method in DomEventListerner to ease user remove callback from DomEventListerner * register IDomEventListerner into DI container instead of create manually * fix FormatKey * fix FormatKey * fix tests * fix test * fix test Co-authored-by: James Yeung <shunjiey@hotmail.com> * fix(module: textarea): replace wrong event (#1927) * tests(module: textarea): include js function mock to avoid bunit exceptions (#1930) * perf(module: overlay): positioning moved to js (#1848) * fix(module:overlay): move postion calculation to js fixes #1836 * docs: TriggerBoundaryAdjustMode explanation * docs: select & datepicker got BoundaryAdjustmetMode cleanup * test: fixes optimization & cleanup * fix(module:overlay): recalculate overlay position when trigger resizes * Minor clean-up * fix(module:overlay): wait for Show to finish in Hide * fix: prevent vertical scrollbar on overlay adding * fix: extract waiting function * fix: overlay not to repostion when trigger vanishes (menu issue) * fix: scroll adjustment for position: fixed * fix: on menu mode change, keep * merge conflict fix * fix: nominal calculation reset on failed adjustment * fix: bugs * test: exclude log method from test coverage in overlay.ts * fix(module: table): It would be load twice at first time if pagesize is not 10 (#1933) * fix(module: menu): collapsed menu title can't hide while use router link (#1934) * fix(module: select): fix data source of type IEnumerable<object> (#1932) * fix(module:select): fix data source of type IEnumerable<object> * Update Select.razor.cs * Update Select.OnDataSourceChangeTests.razor Co-authored-by: James Yeung <shunjiey@hotmail.com> * feat(module: InputNumber): Add OnFocus event (#1931) * Add on textbox focus * Adjust naming Co-authored-by: James Yeung <shunjiey@hotmail.com> * fix(module: list): resposive style doesn't work (#1937) * docs: Update index.zh-CN.md (#1936) Update document ConfigProvider global configuration example code Co-authored-by: James Yeung <shunjiey@hotmail.com> * change log 0.9.4 (#1938) * chore: test cs project to include test runner adapter (#1939) test: add general overlay disposal method mock Co-authored-by: Alan.Liu <lxyruanjian@126.com> Co-authored-by: James Yeung <shunjiey@hotmail.com> Co-authored-by: rabberbock <rabberbock@gmail.com> Co-authored-by: Andrzej Bakun <anddrzejb@poczta.fm> Co-authored-by: Chandan Rauniyar <chandankkrr@gmail.com> Co-authored-by: Luke Parker [SSW] <10430890+Hona@users.noreply.github.com> Co-authored-by: SmallY <45689960+iamSmallY@users.noreply.github.com> Co-authored-by: Maksim <maksalmak@gmail.com> Co-authored-by: Tony Yip <tonyyip1969@gmail.com> Co-authored-by: SmRiley <45205313+SmRiley@users.noreply.github.com>
* fix(module:select): value no longer reset on datasource set * fix(module:select): dataSource change detection * fix: improve datasource detection add item & set value in SelectOption * tests: scenario from issue #1207 * fix: DataSourceEqualityComparer default
* fix(module: form): remove `FormItem` from `Form` when it was disposed (#1901) * pref(module: table): put fixed column style into js (#1897) * pref(module: table): put fixed column style into js * fix resize listener * docs: Add building demo assets to the Readme (#1904) * feat(module: table): add `CellData` for `CellRender` (#1907) * docs: add dynamic table demo (#1908) * feat(module: table): add dynamic data demo * add scroll x * fix(module: select): value no longer reset on datasource set (#1906) * fix(module:select): value no longer reset on datasource set * fix(module:select): dataSource change detection * fix: improve datasource detection add item & set value in SelectOption * tests: scenario from issue #1207 * fix: DataSourceEqualityComparer default * docs: Fixed typo (#1915) * fix(module: input): Add stop propagation (#1917) * docs(module: select): update coordinate demo (#1914) Co-authored-by: James Yeung <shunjiey@hotmail.com> * fix(module: textarea): add rows parameter (#1920) doc: adjust to match antD tests: sizing tests * test(module: select): Add some unit tests for Select (#1891) * Add Select clear tests * Add Select DataSource to null test * Change the implement of Throw tests * Change int to int? * fix(module: button): loading icon styles (#1902) * Fix loading icon styles * Fix button render test * feat(module: InputNumber): Add inputmode for mobile keyboard (#1923) * perf: avoid memory leak issue of event listener (#1857) * perf: avoid memory leak #1834 Avoid memory leak by remove the exclusive parameter and logic in the code block on AddEventListener method in DomEventService class. The following are the components affected: components/affix/Affix.razor.cs components/anchor/Anchor.razor.cs components/carousel/Carousel.razor.cs components/core/Component/Overlay/Overlay.razor.cs components/core/Component/Overlay/OverlayTrigger.razor.cs components/core/JsInterop/DomEventService.cs components/descriptions/Descriptions.razor.cs components/dropdown/DropdownButton.cs components/grid/Row.razor.cs components/input/Input.cs components/input/TextArea.razor.cs components/layout/Sider.razor.cs components/list/ListItem.razor.cs components/select/Select.razor.cs components/select/internal/SelectContent.razor.cs components/slider/Slider.razor.cs components/table/Table.razor.cs components/tabs/Tabs.razor.cs * fix override AddEventListener method in AntDesign.TestKit project * add register/remove event listerner for exclusive use in DomEventService class * move _dotNetObjects to DomEventListerner class/service, so that users not required to maintain it in each component. * * move share/reuse dom event listerner methods to DomEventListerner class * remove method 'AddEventListener' that no longer exists in DomEventService class in AntDesign.TestKit project * * change the component referring to an IDomEventListerner interface instead of a concrete class, so that the component can be tested via a mock TestDomEventListerner. * introduce DisposeShared and Dispose method in DomEventListerner to ease user remove callback from DomEventListerner * register IDomEventListerner into DI container instead of create manually * fix FormatKey * fix FormatKey * fix tests * fix test * fix test Co-authored-by: James Yeung <shunjiey@hotmail.com> * fix(module: textarea): replace wrong event (#1927) * tests(module: textarea): include js function mock to avoid bunit exceptions (#1930) * perf(module: overlay): positioning moved to js (#1848) * fix(module:overlay): move postion calculation to js fixes #1836 * docs: TriggerBoundaryAdjustMode explanation * docs: select & datepicker got BoundaryAdjustmetMode cleanup * test: fixes optimization & cleanup * fix(module:overlay): recalculate overlay position when trigger resizes * Minor clean-up * fix(module:overlay): wait for Show to finish in Hide * fix: prevent vertical scrollbar on overlay adding * fix: extract waiting function * fix: overlay not to repostion when trigger vanishes (menu issue) * fix: scroll adjustment for position: fixed * fix: on menu mode change, keep * merge conflict fix * fix: nominal calculation reset on failed adjustment * fix: bugs * test: exclude log method from test coverage in overlay.ts * fix(module: table): It would be load twice at first time if pagesize is not 10 (#1933) * fix(module: menu): collapsed menu title can't hide while use router link (#1934) * fix(module: select): fix data source of type IEnumerable<object> (#1932) * fix(module:select): fix data source of type IEnumerable<object> * Update Select.razor.cs * Update Select.OnDataSourceChangeTests.razor Co-authored-by: James Yeung <shunjiey@hotmail.com> * feat(module: InputNumber): Add OnFocus event (#1931) * Add on textbox focus * Adjust naming Co-authored-by: James Yeung <shunjiey@hotmail.com> * fix(module: list): resposive style doesn't work (#1937) * docs: Update index.zh-CN.md (#1936) Update document ConfigProvider global configuration example code Co-authored-by: James Yeung <shunjiey@hotmail.com> * change log 0.9.4 (#1938) * chore: test cs project to include test runner adapter (#1939) test: add general overlay disposal method mock Co-authored-by: Alan.Liu <lxyruanjian@126.com> Co-authored-by: James Yeung <shunjiey@hotmail.com> Co-authored-by: rabberbock <rabberbock@gmail.com> Co-authored-by: Andrzej Bakun <anddrzejb@poczta.fm> Co-authored-by: Chandan Rauniyar <chandankkrr@gmail.com> Co-authored-by: Luke Parker [SSW] <10430890+Hona@users.noreply.github.com> Co-authored-by: SmallY <45689960+iamSmallY@users.noreply.github.com> Co-authored-by: Maksim <maksalmak@gmail.com> Co-authored-by: Tony Yip <tonyyip1969@gmail.com> Co-authored-by: SmRiley <45205313+SmRiley@users.noreply.github.com>
🤔 This is a ...
🔗 Related issue link
Fixes #1719
Fixes #1905
💡 Background and solution
I found out that issue #1905 was basically caused by PR #1720. I did a deeper dive and I found out that the solution employed by @anranruye was causing additional re-render and resetting of the bound value. The problem was that when
DataSource
changes, thenOnValueChanged
is called which is trying to find currentValue
in theSelectOptionItems
. If nothing is matching inSelectOptionItems
, then theValue
is set todefault
. The thing is,SelectOptionItems
might not yet be populated withDataSource
. Thus, I added populating of theSelectOptionItems
ifDataSource
change is detected (and added aboolean _alredyRecreatedSelectOptions
to prevent multiple recreation ofSelectOptionItems
inCreateDeleteSelectOptions()
method. I also rolled back the changes of PR #1720.I also added the tests to cover the issues.
📝 Changelog
☑️ Self Check before Merge