Skip to content

Commit

Permalink
🩹 fix: resize list container when the inputs size changes. Fixes #88
Browse files Browse the repository at this point in the history
  • Loading branch information
niketpathak committed Oct 3, 2024
1 parent d0e5307 commit d608b63
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/typeahead-standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ const typeahead = <T extends Dictionary>(config: typeaheadConfig<T>): typeaheadR
listContainer.style.width = `${input.offsetWidth}px`;
listContainer.style.marginTop = `${input.offsetHeight + parseInt(computedInputStyle.marginTop)}px`;

// watch the input for changes in width and update the list container accordingly
const inputResizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
listContainer.style.width = `${(entry.target as HTMLElement).offsetWidth}px`;
}
});
inputResizeObserver.observe(input);

// Attach list container
wrapper.appendChild(listContainer);

Expand Down

0 comments on commit d608b63

Please sign in to comment.