fix: Canvas icon cannot be dragged or dropped#3951
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| > | ||
| <component | ||
| :is="iconComponent(`${nodeModel.type}-icon`)" | ||
| class="mr-8" |
There was a problem hiding this comment.
The given code snippet has several potential issues that could be addressed:
-
Multiple Drag Event Handlers: The
@dragstart,@drag,@dragover, and@dragendevents seem unnecessary here. These should only be attached to the element being dragged, not its container. -
Inline Styles: Using inline styles like
style="width: 70%"can increase complexity and potentially lead to reflows if the parent's dimensions change. Consider using CSS classes instead. -
Component Lifecycle Concerns: The
v-resizedirective might interfere with drag behavior because it likely uses event listeners or animations within itself. Ensure that these directives do not conflict with any existing drag handling logic. -
Flexbox Alignment: The
align-centerclass in both components suggests center alignment, which may not work properly with dynamic widths. Verify that all children of these divs have consistent sizing.
Here is an improved version of the code:
<div v-resize="resizeStepContainer">
<div class="flex-between">
<div v-draggable
@draggableenter.prevent @draggableresume.prevent @draggableleave.prevent
ondragmove="onDragMove(event)" ondragend="onDragEnd(event)"
class="flex align-end mr-8"
style="width: 70%">
<component :is="iconComponent(`${nodeModel.type}-icon`)"/>
</div>
</div>
</div>
<script>
// Example implementation of draggable and resizing logic
export default {
methods: {
onClick() { /* Your click handler */ },
resizeStepContainer({ newSize }) {/* Your resize logic */ }
// Add custom drag handlers
onDragMove(event) {}, onDragEnd(event) {}
}
}
</script>
<style scoped>
/* Use css flexbox styling for centered alignment */
.flex-between > * {
align-self: center;
}
.dragging {
position: relative; !important /* Adjust positioning as needed */
}
#container {
width: 100%; /* Full width */
}
</style>Key Corrections Made:
-
Removed Unnecessary Events: Only
@mousemove,@mouseup, and possibly other necessary drag-related events are typically required on the draggable target. -
Separated Draggable Logic: Added specific drag related JavaScript methods (
onClick,resizeStepContainer) in addition to Vue lifecycle hooks (likemounted(), computed(): {}). -
Optimized Inline Styles: Removed inline styles from child components where possible and used external or scoped CSS for better performance and maintainability.
This refactored version assumes you need custom drag interaction and handles those behaviors separately, thus improving readability and efficiency.
fix: Canvas icon cannot be dragged or dropped