This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: The getOptimalPosition utility should consider limiter ancestors…
… with CSS overflow. Closes #148.
- Loading branch information
Showing
5 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<div class="wrapper"> | ||
<div class="limiter"> | ||
<div class="target"></div> | ||
</div> | ||
|
||
<div class="source"></div> | ||
</div> | ||
|
||
|
||
<style> | ||
.wrapper { | ||
overflow: scroll; | ||
outline: 1px solid #000; | ||
height: 400px; | ||
position: relative; | ||
padding: 20px; | ||
margin-top: 100px; | ||
} | ||
|
||
.limiter { | ||
height: 500px; | ||
overflow: hidden; | ||
} | ||
|
||
.target { | ||
height: 150px; | ||
background: #ccc; | ||
width: 50px; | ||
margin: 170px auto 0; | ||
} | ||
|
||
.source { | ||
height: 50px; | ||
width: 50px; | ||
background: red; | ||
position: absolute; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/* global document */ | ||
|
||
import { getOptimalPosition } from '@ckeditor/ckeditor5-utils/src/dom/position'; | ||
|
||
const source = document.querySelector( '.source' ); | ||
const target = document.querySelector( '.target' ); | ||
const limiter = document.querySelector( '.limiter' ); | ||
const positions = { | ||
above: ( targetRect, sourceRect ) => ( { | ||
top: targetRect.top - sourceRect.height - 50, | ||
left: targetRect.left, | ||
name: 'above' | ||
} ), | ||
below: ( targetRect ) => ( { | ||
top: targetRect.bottom + 50, | ||
left: targetRect.left, | ||
name: 'below' | ||
} ) | ||
}; | ||
|
||
function updateSourcePosition() { | ||
const position = getOptimalPosition( { | ||
element: source, | ||
target: target, | ||
positions: [ | ||
positions.above, | ||
positions.below, | ||
], | ||
limiter: limiter | ||
} ); | ||
|
||
source.style.top = position.top + 'px'; | ||
source.style.left = position.left + 'px'; | ||
} | ||
|
||
updateSourcePosition(); | ||
|
||
document.addEventListener( 'scroll', updateSourcePosition, true ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
### `getOptimalPosition()` with the `limiter` resticted by overflowed parents [#146](https://github.com/ckeditor/ckeditor5-utils/issues/148) | ||
|
||
Vertically scroll the container up and down. | ||
|
||
**Expected**: | ||
|
||
1. The red square should **always** remain visible regardless of the position of the scroll. | ||
2. In the initial position, the shapes should represent a small letter "i", with the red dot above. | ||
3. In the opposite scroll position, the shapes should represent an exclamation mark "!" with the red dot underneath. |