mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	Make accordion expand dependent on text width
This commit is contained in:
		
							parent
							
								
									ffc0c0a229
								
							
						
					
					
						commit
						e33ed6b8e7
					
				| @ -35,26 +35,30 @@ export const ConstraintAccordionView = ({ | |||||||
|         constraint.operator |         constraint.operator | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|     const handleChange = |     const handleClick = ()  => { | ||||||
|         () => (event: React.SyntheticEvent, isExpanded: boolean) => { |         console.log('click') | ||||||
|             setExpanded((!isExpanded && expandable)); |         if (expandable) { | ||||||
|         }; |             setExpanded(!expanded); | ||||||
|  |         } | ||||||
|  |     }; | ||||||
| 
 | 
 | ||||||
|     return ( |     return ( | ||||||
|         <Accordion |         <Accordion | ||||||
|             className={styles.accordion} |             className={styles.accordion} | ||||||
|             classes={{ root: styles.accordionRoot }} |             classes={{ root: styles.accordionRoot }} | ||||||
|             expanded={expanded} |             expanded={expanded} | ||||||
|             onChange={handleChange} |  | ||||||
|         > |         > | ||||||
|             <AccordionSummary className={styles.summary} expandIcon={null}> |             <AccordionSummary className={styles.summary} expandIcon={null} onClick={handleClick}> | ||||||
|                 <ConstraintAccordionViewHeader |                 <ConstraintAccordionViewHeader | ||||||
|                     compact={compact} |                     compact={compact} | ||||||
|                     constraint={constraint} |                     constraint={constraint} | ||||||
|                     onEdit={onEdit} |                     onEdit={onEdit} | ||||||
|                     onDelete={onDelete} |                     onDelete={onDelete} | ||||||
|                     singleValue={singleValue} |                     singleValue={singleValue} | ||||||
|                     allowExpand={(shouldExpand) => setExpandable(shouldExpand)} |                     allowExpand={(shouldExpand) => { | ||||||
|  |                         console.log(shouldExpand) | ||||||
|  |                         setExpandable(shouldExpand) | ||||||
|  |                     }} | ||||||
|                 /> |                 /> | ||||||
|             </AccordionSummary> |             </AccordionSummary> | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -89,13 +89,13 @@ export const ConstraintAccordionViewHeader = ({ | |||||||
| 
 | 
 | ||||||
|     useEffect(() => { |     useEffect(() => { | ||||||
|         if (elementRef && elementRef.current != null) { |         if (elementRef && elementRef.current != null) { | ||||||
|             console.log(elementRef.current.clientHeight); |  | ||||||
|             console.log(elementRef.current.clientWidth); |  | ||||||
|             setTextWidth( |             setTextWidth( | ||||||
|                 Math.round(getTextWidth(elementRef.current.innerText) / 2) // 2 lines
 |                 Math.round(getTextWidth(elementRef.current.innerText) / 2) // 2 lines
 | ||||||
|             ); |             ); | ||||||
|             setHeight(elementRef.current.clientHeight); |             setHeight(elementRef.current.clientHeight); | ||||||
|             setWidth(elementRef.current.clientWidth); |             setWidth(elementRef.current.clientWidth); | ||||||
|  |             console.log(textWidth) | ||||||
|  |             console.log(width) | ||||||
|             allowExpand(textWidth > width) |             allowExpand(textWidth > width) | ||||||
|         } |         } | ||||||
|     }, []); |     }, []); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user