Skip to content

Commit 9549355

Browse files
authored
Tooltip misplaced (#3499)
* fix bug: tooltip misplaced * Transition only opacity attributes
1 parent 88e8d2e commit 9549355

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

browser/components/StorageItem.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ const FolderIcon = ({ className, color, isActive }) => {
2121

2222
/**
2323
* @param {boolean} isActive
24+
* @param {object} tooltipRef,
2425
* @param {Function} handleButtonClick
26+
* @param {Function} handleMouseEnter
2527
* @param {Function} handleContextMenu
2628
* @param {string} folderName
2729
* @param {string} folderColor
@@ -35,7 +37,9 @@ const FolderIcon = ({ className, color, isActive }) => {
3537
const StorageItem = ({
3638
styles,
3739
isActive,
40+
tooltipRef,
3841
handleButtonClick,
42+
handleMouseEnter,
3943
handleContextMenu,
4044
folderName,
4145
folderColor,
@@ -49,6 +53,7 @@ const StorageItem = ({
4953
<button
5054
styleName={isActive ? 'folderList-item--active' : 'folderList-item'}
5155
onClick={handleButtonClick}
56+
onMouseEnter={handleMouseEnter}
5257
onContextMenu={handleContextMenu}
5358
onDrop={handleDrop}
5459
onDragEnter={handleDragEnter}
@@ -75,15 +80,19 @@ const StorageItem = ({
7580
<span styleName='folderList-item-noteCount'>{noteCount}</span>
7681
)}
7782
{isFolded && (
78-
<span styleName='folderList-item-tooltip'>{folderName}</span>
83+
<span styleName='folderList-item-tooltip' ref={tooltipRef}>
84+
{folderName}
85+
</span>
7986
)}
8087
</button>
8188
)
8289
}
8390

8491
StorageItem.propTypes = {
8592
isActive: PropTypes.bool.isRequired,
93+
tooltipRef: PropTypes.object,
8694
handleButtonClick: PropTypes.func,
95+
handleMouseEnter: PropTypes.func,
8796
handleContextMenu: PropTypes.func,
8897
folderName: PropTypes.string.isRequired,
8998
folderColor: PropTypes.string,

browser/components/StorageItem.styl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
border-bottom-right-radius 2px
6161
height 34px
6262
line-height 32px
63+
transition-property opacity
6364

6465
.folderList-item:hover, .folderList-item--active:hover
6566
.folderList-item-tooltip

browser/main/SideNav/StorageItem.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ class StorageItem extends React.Component {
144144
}
145145
}
146146

147+
handleFolderMouseEnter(e, tooltipRef, isFolded) {
148+
if (isFolded) {
149+
const buttonEl = e.currentTarget
150+
const tooltipEl = tooltipRef.current
151+
152+
tooltipEl.style.top = buttonEl.getBoundingClientRect().y + 'px'
153+
}
154+
}
155+
147156
handleFolderButtonContextMenu(e, folder) {
148157
context.popup([
149158
{
@@ -316,6 +325,7 @@ class StorageItem extends React.Component {
316325
folder.key
317326
)
318327
const isActive = !!location.pathname.match(folderRegex)
328+
const tooltipRef = React.createRef(null)
319329
const noteSet = folderNoteMap.get(storage.key + '-' + folder.key)
320330

321331
let noteCount = 0
@@ -339,7 +349,11 @@ class StorageItem extends React.Component {
339349
key={folder.key}
340350
index={index}
341351
isActive={isActive || folder.key === this.state.draggedOver}
352+
tooltipRef={tooltipRef}
342353
handleButtonClick={e => this.handleFolderButtonClick(folder.key)(e)}
354+
handleMouseEnter={e =>
355+
this.handleFolderMouseEnter(e, tooltipRef, isFolded)
356+
}
343357
handleContextMenu={e => this.handleFolderButtonContextMenu(e, folder)}
344358
folderName={folder.name}
345359
folderColor={folder.color}

0 commit comments

Comments
 (0)