- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 621
Fix/gap fixed columns shadow #1202
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
          
     Open
      
      
            bbb169
  wants to merge
  7
  commits into
  react-component:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
bbb169:fix/gap-fixed-columns-shadow
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      1481096
              
                fix: gab fixed columns have no shadow
              
              
                bbb169 0263215
              
                fix: supplement styles changes
              
              
                bbb169 28351f0
              
                feat: use `getBoundingClientRect` to calculate dom whether is sticky
              
              
                bbb169 e3d3287
              
                fix: add `getBoundingClientRect` spy to pass tests
              
              
                bbb169 04091fc
              
                fix: tsc check error
              
              
                bbb169 99b1309
              
                chore: optimize codes logic
              
              
                bbb169 e862c63
              
                feat: add test case for fixed gap columns scrolling
              
              
                bbb169 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
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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 | 
|---|---|---|
|  | @@ -22,6 +22,8 @@ export interface CellProps<RecordType extends DefaultRecordType> { | |
| record?: RecordType; | ||
| /** `column` index is the real show rowIndex */ | ||
| index?: number; | ||
| /** the column index which cell in */ | ||
| colIndex?: number; | ||
| /** the index of the record. For the render(value, record, renderIndex) */ | ||
| renderIndex?: number; | ||
| dataIndex?: DataIndex<RecordType>; | ||
|  | @@ -72,7 +74,10 @@ const getTitleFromCellRenderChildren = ({ | |
| return title; | ||
| }; | ||
|  | ||
| function Cell<RecordType>(props: CellProps<RecordType>) { | ||
| function Cell<RecordType>( | ||
| props: CellProps<RecordType>, | ||
| ref: React.ForwardedRef<HTMLTableCellElement>, | ||
| ) { | ||
| if (process.env.NODE_ENV !== 'production') { | ||
| devRenderTimes(props); | ||
| } | ||
|  | @@ -99,6 +104,9 @@ function Cell<RecordType>(props: CellProps<RecordType>) { | |
| index, | ||
| rowType, | ||
|  | ||
| // Col, | ||
| colIndex, | ||
|  | ||
| // Span | ||
| colSpan, | ||
| rowSpan, | ||
|  | @@ -118,11 +126,14 @@ function Cell<RecordType>(props: CellProps<RecordType>) { | |
| } = props; | ||
|  | ||
| const cellPrefixCls = `${prefixCls}-cell`; | ||
| const { supportSticky, allColumnsFixedLeft, rowHoverable } = useContext(TableContext, [ | ||
| 'supportSticky', | ||
| 'allColumnsFixedLeft', | ||
| 'rowHoverable', | ||
| ]); | ||
| const { supportSticky, allColumnsFixedLeft, rowHoverable, bodyScrollLeft, headerCellRefs } = | ||
| useContext(TableContext, [ | ||
| 'supportSticky', | ||
| 'allColumnsFixedLeft', | ||
| 'rowHoverable', | ||
| 'bodyScrollLeft', | ||
| 'headerCellRefs', | ||
| ]); | ||
|  | ||
| // ====================== Value ======================= | ||
| const [childNode, legacyCellProps] = useCellRender( | ||
|  | @@ -171,6 +182,19 @@ function Cell<RecordType>(props: CellProps<RecordType>) { | |
| additionalProps?.onMouseLeave?.(event); | ||
| }); | ||
|  | ||
| const mergedLastFixLeft = React.useMemo(() => { | ||
| const { current } = headerCellRefs; | ||
| const dom = current[colIndex]; | ||
|  | ||
| if (lastFixLeft && dom && typeof fixLeft === 'number') { | ||
| const offsetLeft = | ||
| dom.getBoundingClientRect().x - dom.parentElement.getBoundingClientRect().x || 0; | ||
|  | ||
| // should not be tagged as lastFixLeft if cell is not stickying; | ||
| return offsetLeft === fixLeft + bodyScrollLeft; | ||
| } | ||
| return lastFixLeft; | ||
| }, [bodyScrollLeft, colIndex, fixLeft, headerCellRefs, lastFixLeft]); | ||
| // ====================== Render ====================== | ||
| if (mergedColSpan === 0 || mergedRowSpan === 0) { | ||
| return null; | ||
|  | @@ -192,8 +216,8 @@ function Cell<RecordType>(props: CellProps<RecordType>) { | |
| { | ||
| [`${cellPrefixCls}-fix-left`]: isFixLeft && supportSticky, | ||
| [`${cellPrefixCls}-fix-left-first`]: firstFixLeft && supportSticky, | ||
| [`${cellPrefixCls}-fix-left-last`]: lastFixLeft && supportSticky, | ||
| [`${cellPrefixCls}-fix-left-all`]: lastFixLeft && allColumnsFixedLeft && supportSticky, | ||
| [`${cellPrefixCls}-fix-left-last`]: mergedLastFixLeft && supportSticky, | ||
| 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. 直接拆解出来,多做一个 div holder 专门用来绘制阴影,也不用依赖 cell 了。 | ||
| [`${cellPrefixCls}-fix-left-all`]: mergedLastFixLeft && allColumnsFixedLeft && supportSticky, | ||
| [`${cellPrefixCls}-fix-right`]: isFixRight && supportSticky, | ||
| [`${cellPrefixCls}-fix-right-first`]: firstFixRight && supportSticky, | ||
| [`${cellPrefixCls}-fix-right-last`]: lastFixRight && supportSticky, | ||
|  | @@ -237,6 +261,7 @@ function Cell<RecordType>(props: CellProps<RecordType>) { | |
|  | ||
| return ( | ||
| <Component | ||
| ref={ref} | ||
| {...legacyCellProps} | ||
| {...additionalProps} | ||
| className={mergedClassName} | ||
|  | @@ -257,4 +282,6 @@ function Cell<RecordType>(props: CellProps<RecordType>) { | |
| ); | ||
| } | ||
|  | ||
| export default React.memo(Cell) as typeof Cell; | ||
| export default React.memo(React.forwardRef(Cell)) as <RecordType>( | ||
| props: CellProps<RecordType> & { ref?: React.ForwardedRef<HTMLTableCellElement> }, | ||
| ) => React.JSX.Element; | ||
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
    
  
  
    
              
      
      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.
不能在 render 阶段调用 dom 逻辑,这个在 SSR 环境下会导致注水失败。