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

Allow customisation / unrestrict suggestions width #31

Closed
antony opened this issue Jul 19, 2019 · 2 comments
Closed

Allow customisation / unrestrict suggestions width #31

antony opened this issue Jul 19, 2019 · 2 comments

Comments

@antony
Copy link

antony commented Jul 19, 2019

Great autocomplete! It works well. One thing which is problematic for me though is the style attributes given to the autocomplete div when it opens, namely, the restriction of the dropdown's width to the offsetwidth of the input.

For addresses and similar, this results in very long, crushed up text in the autocomplete results.

It would be great if there were a way to override this restriction.

@kraaden
Copy link
Owner

kraaden commented Jul 19, 2019

Hi Antony,

You can manually specify width like this:

autocomplete({
    ...
    customize: function(input, inputRect, container) {
        container.style.width = "100px";
    }
});

and you can also modify the default behaviour and use it everywhere in your web app, so you don't need to override it every time you use autocomplete:

export default function autocompleteCustomized<T extends AutocompleteItem>(settings: AutocompleteSettings<T>): AutocompleteResult {
    return autocomplete({
        ...settings,
        customize: (input: HTMLInputElement, inputRect: ClientRect | DOMRect, container: HTMLDivElement) => {
            container.style.width = "100px";
        }
    });
}

@kraaden kraaden closed this as completed Jul 25, 2019
@antony
Copy link
Author

antony commented Jul 25, 2019

Thanks for this - perfect solution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants