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

refactor(ui5-input): events changes #8769

Merged
merged 29 commits into from
May 8, 2024
Merged

refactor(ui5-input): events changes #8769

merged 29 commits into from
May 8, 2024

Conversation

nikoletavnv
Copy link
Member

@nikoletavnv nikoletavnv commented Apr 16, 2024

Remove suggestion-item-select event for ui5-input component. Remove previewItem property for ui5-input component. Rename event suggestion-item-preview to selection-change.

BREAKING CHANGE:
The suggestion-item-select event is no longer present for ui5-input component. Instead, the users can listen for the change event when a suggestion item is selected as input value.
The event suggestion-item-preview is replaced by selection-change event. It is fired when the user navigates among the suggestion items using the ARROWS keys. Also selection-change event is fired when the user opens the suggestions popover and directly clicks on a suggestion item, that is not marked as "selected" at the moment. The parameters dispatched with the selection-change event remain the same as the ones dispatched with the old suggestion-item-preview event.
The property previewItem, that returned the current suggestion item on preview, is no longer present. The user can listen for selection-change event in order to understand which suggestion item is on preview.

  • Input event 'suggestion-item-preview' was renamed to 'selection-change'

If you have previously attached to 'suggestion-item-preview' event:

input.addEventListener("ui5-suggestion-item-preview", event => { const { item, targetRef } = event.detail;});

Now you should attach to 'selection-change' event:

input.addEventListener("ui5-selection-change", event => { const { item, targetRef } = event.detail;});

The event details remain the same. The only difference is that item and targetRef may be null, because 'selection-change' event is also fired when the input value no longer matches a selected suggestion.

  • Deleted event 'suggestion-item-select'

If you have previously listened to 'suggestion-item-select' event to detect which suggestion item has been selected by the user:

input.addEventListener("ui5-suggestion-item-select", event => { 
	const suggestionItem = event.detail.item;
	// do something with the suggestion item
});

Now you can detect which suggestion item was selected if you attach to 'selection-change event', keep the selected item in a variable and during 'change' event check if the input value matches the last selected item:

let suggestionItem;

input.addEventListener("ui5-selection-change", (event) => {
   suggestionItem = event.detail.item; 		 
});

input.addEventListener("ui5-change", (event) => {
  if(event.target.value && suggestionItem && 
     (event.target.value === suggestionItem.text)){
    // do something with the suggestion item
    console.log(suggestionItem);
  }
});
  • Removed property 'previewItem'

Accesing the suggestion item under preview was done like this:

const suggestionItemOnPreview = input.previewItem;

Now you can attach to 'selection-change' event and get the previewed suggestion item from the event detail:

input.addEventListener("ui5-selection-change", event => { 
	const suggestionItemOnPreview = event.detail.item;
});

Related to: #8461

BREAKING CHANGE: Remove suggestion-item-select event.
Rename and modify suggestion-item-preview event.
Remove openPicker method and replace it with public property "open".
@nikoletavnv nikoletavnv changed the title WIP: refactor(ui5-input): events changes refactor(ui5-input): events changes Apr 22, 2024
@nikoletavnv nikoletavnv marked this pull request as ready for review April 22, 2024 15:01
packages/main/src/Input.ts Outdated Show resolved Hide resolved
packages/main/src/Input.ts Show resolved Hide resolved
@@ -49,7 +48,7 @@ type MultiInputTokenDeleteEventDetail = {
* Fiori Guidelines say that user should create tokens when:
*
* - Type a value in the input and press enter or focus out the input field (`change` event is fired)
* - Select a value from the suggestion list (`suggestion-item-select` event is fired)
* - Move between suggestion items or select suggestion item (`selection-change` event is fired)
Copy link
Contributor

@ndeshev ndeshev Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is not clear. We fire 'selection-change' when moving (navigating) between suggestions, when an item is selected with click or ENTER we also fire a 'change' event to mark the end of the interaction

packages/main/test/pages/Input.html Outdated Show resolved Hide resolved
packages/main/test/specs/Input.mobile.spec.js Outdated Show resolved Hide resolved
@ndeshev
Copy link
Contributor

ndeshev commented Apr 25, 2024

If one item is selected (with Enter or click) and then the same item is selected again, change event is being fired, which is not correct.

@nikoletavnv
Copy link
Member Author

I created a new bug regarding improper firing of the change event - #8912

@nikoletavnv nikoletavnv merged commit 9f5c8a4 into main May 8, 2024
10 checks passed
@nnaydenow nnaydenow deleted the input-events branch May 29, 2024 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants