Giter VIP home page Giter VIP logo

Comments (2)

vuthanhdanh080200 avatar vuthanhdanh080200 commented on July 20, 2024 1

It's working now. Thank you for your fastly answer @endigo9740. Here is my code for anyone needed.

<script lang="ts">
	import {
		InputChip,
		Autocomplete,
		popup,
		type PopupSettings,
		type AutocompleteOption,
	} from '@skeletonlabs/skeleton';
	import type { SizeOptions } from '@floating-ui/dom';

	import { uniqueId } from 'lodash';

	let inputChip = '';
	let inputChipList = ['vanilla', 'chocolate'];
	type FlavorOption = AutocompleteOption<string, { healthy: boolean }>;
	const flavorOptions: FlavorOption[] = [
		{ label: 'Vanilla', value: 'vanilla', keywords: 'plain, basic', meta: { healthy: false } },
		{ label: 'Chocolate', value: 'chocolate', keywords: 'dark, white', meta: { healthy: false } },
		{ label: 'Strawberry', value: 'strawberry', keywords: 'fruit', meta: { healthy: true } },
		{
			label: 'Neapolitan',
			value: 'neapolitan',
			keywords: 'mix, strawberry, chocolate, vanilla',
			meta: { healthy: false },
		},
		{ label: 'Pineapple', value: 'pineapple', keywords: 'fruit', meta: { healthy: true } },
		{ label: 'Peach', value: 'peach', keywords: 'fruit', meta: { healthy: true } },
	];

	function onInputChipSelect(event: CustomEvent<FlavorOption>): void {
		console.log('onInputChipSelect', event.detail);
		if (inputChipList.includes(event.detail.value) === false) {
			inputChipList = [...inputChipList, event.detail.value];
			inputChip = '';
		}
	}

	const uuid = uniqueId('multiple-select-popup');

	let popupSettings: PopupSettings = {
		event: 'focus-click',
		target: uuid,
		placement: 'bottom-start',
		middleware: {
			shift: {
				padding: 0,
			},
			offset: 0,
			size: {
				apply({ rects, elements }) {
					Object.assign(elements.floating.style, {
						width: `${rects.reference.width}px`,
					});
				},
			} as SizeOptions,
		},
	};
</script>

<div use:popup={popupSettings} class="w-full">
	<InputChip bind:input={inputChip} bind:value={inputChipList} name="chips" />
	<div data-popup={popupSettings.target} class={`card max-h-48  overflow-y-auto`} tabindex="-1">
		<Autocomplete
			bind:input={inputChip}
			options={flavorOptions}
			denylist={inputChipList}
			on:selection={onInputChipSelect} />
	</div>
</div>

from skeleton.

endigo9740 avatar endigo9740 commented on July 20, 2024

@vuthanhdanh080200 so in your screenshot it looks like your trigger element is very close to the edge of the visible screen. This is notable because Floating UI provides several middleware options for controlling position, including one called shift:
https://floating-ui.com/docs/shift

We utilize this in the popup's default settings, which you can see here:
https://github.com/skeletonlabs/skeleton/blob/master/packages/skeleton/src/lib/utilities/Popup/popup.ts#L59

This essentially sets a padding offset of 8px away from the edge of the screen, so it will never be flush like you may be expecting. This is configurable though, which we cover in the Middleware docs here:
https://www.skeleton.dev/utilities/popups#middleware

Feel free to adjust as needed.

Given this is intended behavior, not a bug, I'll go ahead and close this issue. But if you any follow up questions, feel free to reach out and I'll respond (though it may be tomorrow my time).

from skeleton.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.