Skip to content
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

Pick list events emit inconsistent types #10063

Closed
dasco144 opened this issue Apr 1, 2021 · 2 comments
Closed

Pick list events emit inconsistent types #10063

dasco144 opened this issue Apr 1, 2021 · 2 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@dasco144
Copy link

dasco144 commented Apr 1, 2021

I'm submitting a ...

[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Plunkr Case (Bug Reports)
https://stackblitz.com/edit/github-rb49kh?file=src%2Fapp%2Fapp.component.html

Current behavior
When dragging and dropping a picklist item, an array is emitted, where as when moving via double click or using a transfer button, an object with an items array property is emitted.

The documentation currently states the following:

onMoveToTarget | event.items: Moved items array
onMoveToSource | event.items: Moved items array

Expected behavior
When moving items in either fashion, the types emitted should be the same, as per the documentation.

{
  items: any[]
}

Minimal reproduction of the problem with instructions

  • Add a picklist to your component
  • Setup event bindings for the onMoveToTarget and onMoveToSource ouputs.
  • Observe the outputs for these event bindings when doing a drag and drop, as well as when doing a transfer using the transfer buttons or double click.

What is the motivation / use case for changing the behavior?
To ensure that the documentation is accurate and the behaviour is consistent across all events that use the same event emitters

Please tell us about your environment:
Windows 10
VSCode
npm

  • Angular version: 11.2.7

  • PrimeNG version: 11.3.1

  • Browser: all

  • Language: TypeScript 4.1.5

  • Node (for AoT issues): node --version = v12.20.1

@dasco144
Copy link
Author

dasco144 commented Apr 1, 2021

My proposition is that the EventEmitters should be more strictly typed so that these kind of issues could be picked up at code time.

Please see below where I have adjusted the types emitted to match what is stated in the documentation:

    @Output() onMoveToSource: EventEmitter<{ items: any[] }> = new EventEmitter();

    @Output() onMoveAllToSource: EventEmitter<{ items: any[] }> = new EventEmitter();

    @Output() onMoveAllToTarget: EventEmitter<{ items: any[] }> = new EventEmitter();

    @Output() onMoveToTarget: EventEmitter<{ items: any[] }> = new EventEmitter();

    @Output() onSourceReorder: EventEmitter<{ items: any[] }> = new EventEmitter();

    @Output() onTargetReorder: EventEmitter<{ items: any[] }> = new EventEmitter();

    @Output() onSourceSelect: EventEmitter<{ originalEvent: Event, items: any[] }> = new EventEmitter();

    @Output() onTargetSelect: EventEmitter<{ originalEvent: Event, items: any[] }> = new EventEmitter();

    @Output() onSourceFilter: EventEmitter<{ query: string, items: any[] }> = new EventEmitter();

    @Output() onTargetFilter: EventEmitter<{ query: string, items: any[] }> = new EventEmitter();

Adding the above shows 6 errors with the current emissions in the picklist component.

I can look into creating a PR for this when I get a chance

@yigitfindikli yigitfindikli self-assigned this Apr 1, 2021
@yigitfindikli yigitfindikli added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Apr 1, 2021
@yigitfindikli yigitfindikli added this to the 11.3.2 milestone Apr 1, 2021
@dasco144
Copy link
Author

dasco144 commented May 5, 2021

@yigitfindikli
There still seems be an issue here.

In 11.4.0
When dropping an item, at picklist.ts line 595,
event.item.data is an object. This emits items as an object instead of the expected array.

But when using a transfer button or double click, the emission is an array as expected as per the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

2 participants