-
Notifications
You must be signed in to change notification settings - Fork 273
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(ui5-input): improve lazy loading behaviour #4763
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
98ef70b
fix(ui5-input): improve lazy loading behaviour
MapTo0 c9690d0
fix regresions
MapTo0 a3168b6
add tests
MapTo0 69e30b7
- prevent opening of picker on focus in
MapTo0 bc9800d
Merge remote-tracking branch 'origin/master' into input-lazy-loading
MapTo0 85525e2
hash change
MapTo0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ydKuAqEtZBlQWCoH/ufRUwgv+qU= | ||
XgquM3ggzotOfecoo9jjwDTSvdQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Input Lazy Loading</title> | ||
|
||
<script src="../../webcomponentsjs/webcomponents-loader.js"></script> | ||
<script src="../../resources/bundle.esm.js" type="module"></script> | ||
<script nomodule src="../../resources/bundle.es5.js"></script> | ||
|
||
<style> | ||
.demo-container { | ||
margin-top: 1rem; | ||
border: 1px dashed red; | ||
padding: 2rem; | ||
box-sizing: border-box; | ||
text-align: center; | ||
} | ||
|
||
.demo-container:first-child { | ||
margin-top: 0; | ||
} | ||
|
||
.demo-container h1 { | ||
font-size: 1.5rem; | ||
font-weight: normal; | ||
} | ||
|
||
.devider { | ||
border: 1px solid black; | ||
margin: 1rem; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
|
||
<div class="demo-container"> | ||
<h1>Lazy loading items oninput</h1> | ||
|
||
<ui5-input id="field" show-suggestions></ui5-input> | ||
</div> | ||
|
||
<div class="demo-container"> | ||
<h1>Lazy load items on first type in</h1> | ||
|
||
<ui5-input id="first-type" show-suggestions></ui5-input> | ||
</div> | ||
|
||
<div class="demo-container"> | ||
<h1>Preload items</h1> | ||
|
||
<ui5-input id="preload" show-suggestions></ui5-input> | ||
</div> | ||
|
||
<div class="demo-container"> | ||
<h1>Hardcoded items</h1> | ||
|
||
<ui5-input show-suggestions> | ||
<ui5-suggestion-item>Dryanovo</ui5-suggestion-item> | ||
<ui5-suggestion-item>Gabrovo</ui5-suggestion-item> | ||
<ui5-suggestion-item>Sofia</ui5-suggestion-item> | ||
<ui5-suggestion-item>Yablanitsa</ui5-suggestion-item> | ||
<ui5-suggestion-item>New York</ui5-suggestion-item> | ||
</ui5-input> | ||
</div> | ||
|
||
<div class="devider"></div> | ||
|
||
<div class="demo-container"> | ||
<h1>Lazy loading items oninput</h1> | ||
|
||
<ui5-combobox id="combo-field" show-suggestions></ui5-combobox> | ||
</div> | ||
|
||
<div class="demo-container"> | ||
<h1>Lazy load items on first type in</h1> | ||
|
||
<ui5-combobox id="combo-first-type" show-suggestions></ui5-combobox> | ||
</div> | ||
|
||
<div class="demo-container"> | ||
<h1>Preload items</h1> | ||
|
||
<ui5-combobox id="combo-preload" show-suggestions></ui5-combobox> | ||
</div> | ||
|
||
<div class="demo-container"> | ||
<h1>Hardcoded items</h1> | ||
|
||
<ui5-combobox show-suggestions> | ||
<ui5-cb-item text="Dryanovo"></ui5-cb-item> | ||
<ui5-cb-item text="Gabrovo"></ui5-cb-item> | ||
<ui5-cb-item text="Sofia"></ui5-cb-item> | ||
<ui5-cb-item text="Yablanitsa"></ui5-cb-item> | ||
<ui5-cb-item text="New York"></ui5-cb-item> | ||
</ui5-combobox> | ||
</div> | ||
|
||
|
||
<script> | ||
const entries = [{ key: "A", text: "A" }, { key: "Afg", text: "Afghanistan" }, { key: "Arg", text: "Argentina" }, { key: "Alb", text: "Albania" }, { key: "Arm", text: "Armenia" }, { key: "Alg", text: "Algeria" }, { key: "And", text: "Andorra" }, { key: "Ang", text: "Angola" }, { key: "Ast", text: "Austria" }, { key: "Aus", text: "Australia" }, { key: "Aze", text: "Azerbaijan" }, { key: "Aruba", text: "Aruba" }, { key: "Antigua", text: "Antigua and Barbuda" }, { key: "B", text: "B" }, { key: "Bel", text: "Belarus" }, { key: "Bel", text: "Belgium" }, { key: "Bg", text: "Bulgaria" }, { key: "Bra", text: "Brazil" }, { key: "C", text: "C" }, { key: "Ch", text: "China" }, { key: "Cub", text: "Cuba" }, { key: "Chil", text: "Chili" }, { key: "L", text: "L" }, { key: "Lat", text: "Latvia" }, { key: "Lit", text: "Litva" }, { key: "P", text: "P" }, { key: "Prt", text: "Portugal" }, { key: "S", text: "S" }, { key: "Sen", text: "Senegal" }, { key: "Ser", text: "Serbia" }, { key: "Sey", text: "Seychelles" }, { key: "Sierra", text: "Sierra Leone" }, { key: "Sgp", text: "Singapore" }, { key: "Sint", text: "Sint Maarten" }, { key: "Slv", text: "Slovakia" }, { key: "Slo", text: "Slovenia" }]; | ||
|
||
|
||
const fetchData = async () => { | ||
// load data real API | ||
// return (await (await fetch("https://restcountries.com/v3.1/all")).json()); | ||
|
||
// load data fake request | ||
await new Promise(e => setTimeout(e, 1000)); | ||
|
||
return entries; | ||
}; | ||
|
||
const clearChildren = element => { | ||
while (element.firstChild) { | ||
element.removeChild(element.firstChild); | ||
} | ||
}; | ||
|
||
const fillItems = (itemsData, inputElement, tagName) => { | ||
itemsData.forEach(data => { | ||
const element = document.createElement(tagName); | ||
element.setAttribute("text", data.text); | ||
|
||
inputElement.appendChild(element); | ||
}); | ||
}; | ||
|
||
const filterData = (data, value) => { | ||
return data.filter(entry => { | ||
return entry.text.toLowerCase().startsWith(value.toLowerCase()) | ||
}); | ||
}; | ||
|
||
const enableLazyLoadingOnInput = () => { | ||
document.getElementById("field").addEventListener("ui5-input", async event => { | ||
if (event.target.value === "") { | ||
return clearChildren(event.target); | ||
} | ||
|
||
// load data | ||
const data = await fetchData(); | ||
|
||
// filter data | ||
const filteredData = filterData(data, event.target.value); | ||
|
||
// cleanup old items | ||
clearChildren(event.target); | ||
|
||
// fill new items (posibly redux / react state) | ||
fillItems(filteredData, event.target, "ui5-suggestion-item"); | ||
}); | ||
} | ||
|
||
const enableFirsTypein = () => { | ||
const field = document.getElementById("first-type"); | ||
|
||
field.addEventListener("ui5-input", async event => { | ||
const { value, suggestionItems } = event.target; | ||
|
||
if (value.length === 1 && !suggestionItems.length) { | ||
const data = await fetchData(); | ||
|
||
// fill new items (posibly redux / react state) | ||
fillItems(data, event.target, "ui5-suggestion-item"); | ||
|
||
} else if (!value.length && suggestionItems.length) { | ||
clearChildren(event.target); | ||
} | ||
}); | ||
}; | ||
|
||
const enablePreload = async () => { | ||
const data = await fetchData(); | ||
|
||
fillItems(data, document.getElementById("preload"), "ui5-suggestion-item"); | ||
}; | ||
|
||
enableLazyLoadingOnInput(); | ||
enableFirsTypein(); | ||
enablePreload(); | ||
|
||
const enableCbLazyOnInput = () => { | ||
const cb = document.getElementById("combo-field"); | ||
|
||
cb.addEventListener("ui5-input", async event => { | ||
const { value } = event.target; | ||
|
||
const data = await fetchData(); | ||
|
||
// cleanup old items | ||
clearChildren(event.target); | ||
|
||
// fill new items (posibly redux / react state) | ||
fillItems(data, event.target, "ui5-cb-item"); | ||
}); | ||
}; | ||
|
||
enableCbLazyOnInput(); | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do you think we should add the same thing (this.isTyping = false;) in the _handleChange().
This will prevent the popup from opening when the user has typed something and pressed the "Enter" key before the data is received. Should we consider pressing enter the end of the user interaction in such cases?