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 is out of place #954

Open
live627 opened this issue Mar 15, 2024 · 0 comments
Open

Dropdown is out of place #954

live627 opened this issue Mar 15, 2024 · 0 comments
Labels
Milestone

Comments

@live627
Copy link
Collaborator

live627 commented Mar 15, 2024

From my question on Stack Overflow https://stackoverflow.com/questions/77738288/sceditor-dropdown-is-out-of-place

When I create the sceditor like in the example, the dropdowns that appear when clicking on the font icon appears in its normal place.

  	var textarea = document.getElementById('example');
  	sceditor.create(textarea, {
  		format: 'bbcode',
  		icons: 'monocons',
  		autofocus: true,
  		style: '../minified/themes/content/default.min.css'
  	});

However, once I specify my own toolbar, the dropdown is moved off screen and I have to scroll down for ages to find it.

  	var textarea = document.getElementById('example');
  	sceditor.create(textarea, {
  		format: 'bbcode',
  		icons: 'monocons',
  		autofocus: true,
  		style: '../minified/themes/content/default.min.css',
  		toolbarContainer: document.getElementById('toolbar')
  	});

Any way to correct the positioning while having a custom toolbar?

I eventually figured it out

Custom toolbars are outside the sceditor container, which has a relative position. According to https://stackoverflow.com/a/14107783/4710434

By definition offsetTop returns the top position of the object
relative to the top side of its offsetParent element, in pixels.

Now offsetParent needs to be an element with a position other than
static. If you change the position attribute of scroll element in your
fiddle I get a value of 1012 as opposed to 1110 without the position
attribute.

Therefore, remove the relatie position specifier for .sceditor-container` from the CSS file.

Now, the dropdown is relative to the doucment's body, and must be moved. Fortunately, editor.createDropDown() can be overridden via a simple plugin

	sceditor.plugins.fix = function ()
	{
		let editor;

		this.init = function ()
		{
			editor = this;
			const fn = editor.createDropDown;
			this.createDropDown = function (menuItem, name, content) {
				fn(menuItem, name, content);
				document.body.appendChild(document.querySelector('.sceditor-dropdown'));
			};
		};
	};
@live627 live627 added the Bug label Mar 15, 2024
@samclarke samclarke added this to the v3.3.0 milestone Mar 31, 2024
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

2 participants