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

DropDown: Pull down menu opens to the wrong side #189

Open
Jemt opened this issue Jun 11, 2023 · 3 comments
Open

DropDown: Pull down menu opens to the wrong side #189

Jemt opened this issue Jun 11, 2023 · 3 comments
Labels

Comments

@Jemt
Copy link
Owner

Jemt commented Jun 11, 2023

See https://jsfiddle.net/kvu2qcrm/6/

Try the 3 test cases in the JavaScript code. Notice how the combination of DropDownMaxWidth(600) + DetectBoundaries(true) causes the pull down menu to open to the left side, rather than to the right as expected.

image

Code from JSFiddle

HTML

<div id="Control"></div>

CSS

body
{
	font-family: verdana;
	font-size: 14px;
	color: #333;
}

div#Control
{
	text-align: center;
}

JavaScript

Fit.Events.OnReady(function()
{
	var lv = new Fit.Controls.ListView();
	Fit.Array.ForEach(GetUsers(), function(user)
	{
		lv.AddItem(user.Name, user.Mail);
	});
	
	var dd = new Fit.Controls.DropDown("DropDown1");
	dd.SetPicker(lv);
	dd.MultiSelectionMode(true);
	dd.Width(200);
	dd.DropDownMaxHeight(150);
	dd.InputEnabled(true);
	dd.Render(document.querySelector("#Control"));

	// Try the 3 test cases below.
	// IMPORTANT: Resize viewport of test page to a width of 1100px before testing !!!

	// Test case 1
	// DropDownMaxWidth(9999) causes pull down menu to open to the right side as expected.
	// The pull down menu might exceed the boundaries of the viewport though which is fine.
	//dd.DropDownMaxWidth(9999);
	
	// Test case 2 (BUG)
	// DropDownMaxWidth(600) combined with DetectBoundaries(true)
	// results in pull down menu opening to the left side, even
	// though there is plenty of space to the right side to accommodate
	// the MaxWidth of 600px.
	dd.DropDownMaxWidth(600);
	dd.DetectBoundaries(true);
	
	// Test case 3
	// If we instead of DetectBoundaries(true) uses DetectBoundaries(true, true),
	// then the pulldown menu opens to the right side as one would expect.
	//dd.DropDownMaxWidth(600);
	//dd.DetectBoundaries(true, true);
	
	if (Fit.Browser.IsMobile())
    	dd.Width(100, "%");
});

// ============================
// Get demo data
// ============================

window.GetUsers = function(picker)
{
	var users =
	[
		{ Name: "James Thomson James Thomson James Thomson James Thomson James Thomson James Thomson", Mail: "james@server.com" },
		{ Name: "Hans Törp", Mail: "hans@server.com" },
		{ Name: "Ole Shortsom", Mail: "ole@server.com" },
		{ Name: "Michael Burström", Mail: "michael@server.com" },
		{ Name: "Ilda Longstum", Mail: "ilda@server.com" },
		{ Name: "Martin Grom", Mail: "martin@server.com" },
		{ Name: "Anders Handsom", Mail: "anders@server.com" },
		{ Name: "Jacob Marking", Mail: "jacob@server.com" },
		{ Name: "Jan Jacksson", Mail: "jan@server.com" },
		{ Name: "Christian Fros", Mail: "christian@server.com" }
	];
	
	return users;
}
@Jemt Jemt added the bug label Jun 11, 2023
@Jemt
Copy link
Owner Author

Jemt commented Jun 11, 2023

Here the left/right position is determine for DetectBoundaries(true):

// Open left or right (default)

Here the right/right position is determined for DetectBoundaries(true, true) - relative to viewport:

// Open left or right (defafult)

@Jemt
Copy link
Owner Author

Jemt commented Jun 11, 2023

This also seems less than optimal. If e.g. DropDownMaxWidth(100, "em") is configured, the calculated pixel width will be returned and become the basis of the calculation of space available - but the pull down menu might not even assume a width of 100em - remember, this is max-width, not actual width. It would be better if we could obtain offsetWidth from the pulldown menu instead.

var spaceRequiredRightSide = getDropDownMaxWidthPixelValue(); // DropDownMaxWidth as px value - DropDown menu opens to the side that best accommodates the needed space - opening to the right is preferred

@Jemt
Copy link
Owner Author

Jemt commented Jun 11, 2023

Bonus bug found. If we use DetectBoundaries(true, true) without configuring DropDownMaxWidth(..), then the pull down menu exceeds the boundaries of the viewport: https://jsfiddle.net/7vhewxgq/

image

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

No branches or pull requests

1 participant