-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Lens] Keyboard-selected items follow user traversal of drop zones #90546
Merged
mbondyra
merged 15 commits into
elastic:master
from
mbondyra:lens/dnd_add_ghost_image_to_keyboard_navigation
Feb 15, 2021
Merged
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e19f9ad
adding a ghost image
mbondyra a2f1c14
fix safari fullscreen
mbondyra 97c3393
Merge branch 'master' into lens/dnd_add_ghost_image_to_keyboard_navig…
kibanamachine 464f71c
Merge branch 'master' into lens/dnd_add_ghost_image_to_keyboard_navig…
kibanamachine 548b774
Merge branch 'master' into lens/dnd_add_ghost_image_to_keyboard_navig…
kibanamachine 45dbf89
show ghost instead of noGhost
mbondyra 1c2d223
Merge branch 'master' into lens/dnd_add_ghost_image_to_keyboard_navig…
mbondyra 82c7c22
Merge branch 'master' into lens/dnd_add_ghost_image_to_keyboard_navig…
kibanamachine c13cfd0
cr corrections
mbondyra a84ed51
Merge commit '6bd0a7fcc5f477b75ca173ee0de11ebcd2898f4f' into lens/dnd…
mbondyra 7e2d40d
removing commented code
mbondyra 3eb52e6
remvoing commented code
mbondyra 6f60e55
remvoing commented code
mbondyra 2cef3ea
Update x-pack/plugins/lens/public/drag_drop/drag_drop.scss
mbondyra 1f6aa1a
Merge branch 'master' into lens/dnd_add_ghost_image_to_keyboard_navig…
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
x-pack/plugins/lens/public/drag_drop/__snapshots__/drag_drop.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -93,6 +93,11 @@ interface BaseProps { | |
* Order for keyboard dragging. This takes an array of numbers which will be used to order hierarchically | ||
*/ | ||
order: number[]; | ||
|
||
/** | ||
* don't display ghost image for the drop element | ||
*/ | ||
noGhost?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have a strong feeling here, but we could call the prop
|
||
} | ||
|
||
/** | ||
|
@@ -232,7 +237,7 @@ const DragInner = memo(function DragInner({ | |
|
||
const currentTarget = e?.currentTarget; | ||
setTimeout(() => { | ||
setDragging(value); | ||
setDragging({ ...value, ghost: children }); | ||
setA11yMessage(announce.lifted(value.humanData)); | ||
if (onDragStart) { | ||
onDragStart(currentTarget); | ||
|
@@ -278,8 +283,19 @@ const DragInner = memo(function DragInner({ | |
: announce.noTarget() | ||
); | ||
}; | ||
const shouldShowGhostImageInstead = | ||
isDragging && | ||
dragType === 'move' && | ||
keyboardMode && | ||
activeDropTarget?.activeDropTarget && | ||
activeDropTarget?.activeDropTarget.dropType !== 'reorder'; | ||
return ( | ||
<div className={className} data-test-subj={`lnsDragDrop_draggable-${value.humanData.label}`}> | ||
<div | ||
className={classNames(className, { | ||
'lnsDragDrop-isHidden-noFocus': shouldShowGhostImageInstead, | ||
})} | ||
data-test-subj={`lnsDragDrop_draggable-${value.humanData.label}`} | ||
> | ||
<EuiScreenReaderOnly showOnFocus> | ||
<button | ||
aria-label={value.humanData.label} | ||
|
@@ -305,6 +321,8 @@ const DragInner = memo(function DragInner({ | |
} | ||
} else if (key === keys.ESCAPE) { | ||
if (isDragging) { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
dragEnd(); | ||
} | ||
} | ||
|
@@ -321,7 +339,8 @@ const DragInner = memo(function DragInner({ | |
{React.cloneElement(children, { | ||
'data-test-subj': dataTestSubj || 'lnsDragDrop', | ||
className: classNames(children.props.className, 'lnsDragDrop', 'lnsDragDrop-isDraggable', { | ||
'lnsDragDrop-isHidden': isDragging && dragType === 'move' && !keyboardMode, | ||
'lnsDragDrop-isHidden': | ||
(isDragging && dragType === 'move' && !keyboardMode) || shouldShowGhostImageInstead, | ||
}), | ||
draggable: true, | ||
onDragEnd: dragEnd, | ||
|
@@ -344,6 +363,7 @@ const DropInner = memo(function DropInner(props: DropInnerProps) { | |
isNotDroppable, | ||
dragType = 'copy', | ||
dropType, | ||
noGhost, | ||
keyboardMode, | ||
activeDropTarget, | ||
registerDropTarget, | ||
|
@@ -431,6 +451,15 @@ const DropInner = memo(function DropInner(props: DropInnerProps) { | |
onDrop: drop, | ||
draggable, | ||
})} | ||
{!noGhost && | ||
dragging?.ghost && | ||
activeDropTargetMatches && | ||
keyboardMode && | ||
dropType !== 'reorder' | ||
? React.cloneElement(dragging.ghost, { | ||
className: classNames('lnsDragDrop_ghost', children.props.className), | ||
}) | ||
: null} | ||
</> | ||
); | ||
}); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find negative props somewhat confusing in components. Maybe others do to?
Especially when passing in
false
you end up with a double negative when thinking it through and that can throw people (me, at least) for a loop.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand and it makes sense. However, on the other side, this construction allows us to treat displaying a ghost as a default behaviour without passing extra parameter and that's what I was trying to do here. So for most components, I can do
<DragDrop draggable .../>
and I don't have to addghost = {true}
(or specify a default value in the component). I understand it's a bit on the edge when it comes to readability so I'd like to know the opinion of another person reviewing this 🙏