mirror of
				https://github.com/cinnyapp/cinny.git
				synced 2025-11-04 06:20:28 +03:00 
			
		
		
		
	use aria-react for message hover & focus hooks (#1456)
This commit is contained in:
		
							parent
							
								
									b92b281050
								
							
						
					
					
						commit
						b4e1ced3ed
					
				
					 3 changed files with 1616 additions and 10 deletions
				
			
		
							
								
								
									
										1606
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										1606
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							| 
						 | 
				
			
			@ -56,6 +56,7 @@
 | 
			
		|||
    "prismjs": "1.29.0",
 | 
			
		||||
    "prop-types": "15.8.1",
 | 
			
		||||
    "react": "17.0.2",
 | 
			
		||||
    "react-aria": "3.29.1",
 | 
			
		||||
    "react-autosize-textarea": "7.1.0",
 | 
			
		||||
    "react-blurhash": "0.2.0",
 | 
			
		||||
    "react-dnd": "15.1.2",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,6 +32,7 @@ import React, {
 | 
			
		|||
  useState,
 | 
			
		||||
} from 'react';
 | 
			
		||||
import FocusTrap from 'focus-trap-react';
 | 
			
		||||
import { useHover, useFocusWithin } from 'react-aria';
 | 
			
		||||
import { MatrixEvent, Room } from 'matrix-js-sdk';
 | 
			
		||||
import { Relations } from 'matrix-js-sdk/lib/models/relations';
 | 
			
		||||
import classNames from 'classnames';
 | 
			
		||||
| 
						 | 
				
			
			@ -607,6 +608,8 @@ export const Message = as<'div', MessageProps>(
 | 
			
		|||
    const mx = useMatrixClient();
 | 
			
		||||
    const senderId = mEvent.getSender() ?? '';
 | 
			
		||||
    const [hover, setHover] = useState(false);
 | 
			
		||||
    const { hoverProps } = useHover({ onHoverChange: setHover });
 | 
			
		||||
    const { focusWithinProps } = useFocusWithin({ onFocusWithinChange: setHover });
 | 
			
		||||
    const [menu, setMenu] = useState(false);
 | 
			
		||||
    const [emojiBoard, setEmojiBoard] = useState(false);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -692,9 +695,6 @@ export const Message = as<'div', MessageProps>(
 | 
			
		|||
      </Box>
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    const showOptions = () => setHover(true);
 | 
			
		||||
    const hideOptions = () => setHover(false);
 | 
			
		||||
 | 
			
		||||
    const handleContextMenu: MouseEventHandler<HTMLDivElement> = (evt) => {
 | 
			
		||||
      if (evt.altKey || !window.getSelection()?.isCollapsed) return;
 | 
			
		||||
      const tag = (evt.target as any).tagName;
 | 
			
		||||
| 
						 | 
				
			
			@ -716,8 +716,8 @@ export const Message = as<'div', MessageProps>(
 | 
			
		|||
        highlight={highlight}
 | 
			
		||||
        selected={menu || emojiBoard}
 | 
			
		||||
        {...props}
 | 
			
		||||
        onMouseEnter={showOptions}
 | 
			
		||||
        onMouseLeave={hideOptions}
 | 
			
		||||
        {...hoverProps}
 | 
			
		||||
        {...focusWithinProps}
 | 
			
		||||
        ref={ref}
 | 
			
		||||
      >
 | 
			
		||||
        {!edit && (hover || menu || emojiBoard) && (
 | 
			
		||||
| 
						 | 
				
			
			@ -958,12 +958,11 @@ export const Event = as<'div', EventProps>(
 | 
			
		|||
  ({ className, room, mEvent, highlight, canDelete, messageSpacing, children, ...props }, ref) => {
 | 
			
		||||
    const mx = useMatrixClient();
 | 
			
		||||
    const [hover, setHover] = useState(false);
 | 
			
		||||
    const { hoverProps } = useHover({ onHoverChange: setHover });
 | 
			
		||||
    const { focusWithinProps } = useFocusWithin({ onFocusWithinChange: setHover });
 | 
			
		||||
    const [menu, setMenu] = useState(false);
 | 
			
		||||
    const stateEvent = typeof mEvent.getStateKey() === 'string';
 | 
			
		||||
 | 
			
		||||
    const showOptions = () => setHover(true);
 | 
			
		||||
    const hideOptions = () => setHover(false);
 | 
			
		||||
 | 
			
		||||
    const handleContextMenu: MouseEventHandler<HTMLDivElement> = (evt) => {
 | 
			
		||||
      if (evt.altKey || !window.getSelection()?.isCollapsed) return;
 | 
			
		||||
      const tag = (evt.target as any).tagName;
 | 
			
		||||
| 
						 | 
				
			
			@ -985,8 +984,8 @@ export const Event = as<'div', EventProps>(
 | 
			
		|||
        highlight={highlight}
 | 
			
		||||
        selected={menu}
 | 
			
		||||
        {...props}
 | 
			
		||||
        onMouseEnter={showOptions}
 | 
			
		||||
        onMouseLeave={hideOptions}
 | 
			
		||||
        {...hoverProps}
 | 
			
		||||
        {...focusWithinProps}
 | 
			
		||||
        ref={ref}
 | 
			
		||||
      >
 | 
			
		||||
        {(hover || menu) && (
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue