- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.1k
[WIP/DO NOT MERGE]: update accessibility/keyboard navigation of ApiModal #7958
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
          
     Draft
      
      
            hbuchel
  wants to merge
  5
  commits into
  feature/api-docs-template
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
api-docs-modal-functionality
  
      
      
   
  
    
  
  
  
 
  
      
    base: feature/api-docs-template
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.
          
          
  
     Draft
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            5 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      cdda093
              
                update Modal styling/ add Breadcrumbs
              
              
                hbuchel d11d495
              
                remove commented out code
              
              
                hbuchel 86aeb85
              
                add keyboard navigation to ApiModal
              
              
                hbuchel ba2139f
              
                merge latest
              
              
                hbuchel ab16ab5
              
                add click outside to close, escape key functionality
              
              
                hbuchel 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,10 +1,21 @@ | ||
| import { useState, createContext } from 'react'; | ||
| import { useState, createContext, useRef, RefObject } from 'react'; | ||
| import { LinkDataType } from './display/TypeLink'; | ||
| import { ApiModal } from './display/ApiModal'; | ||
|  | ||
| export const TypeContext = createContext({ | ||
| interface TypeContextInterface { | ||
| setModalData: (data: any) => void; | ||
| setModalTriggerRef: (ref: RefObject<HTMLButtonElement> | null) => void; | ||
| modalTriggerRef: RefObject<HTMLButtonElement> | null; | ||
| openModal: () => void; | ||
| addBreadCrumb: (data: any) => void; | ||
| setBC: (data: any) => void; | ||
| } | ||
|  | ||
| export const TypeContext = createContext<TypeContextInterface>({ | ||
| setModalData: (data) => data, | ||
| modalOpen: () => {}, | ||
| setModalTriggerRef: (ref) => ref, | ||
| modalTriggerRef: null, | ||
| openModal: () => {}, | ||
| 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. I renamed  | ||
| addBreadCrumb: (data) => data, | ||
| setBC: (data) => data | ||
| }); | ||
|  | @@ -13,12 +24,26 @@ export const ApiModalProvider = ({ children }) => { | |
| const [modalData, setModalData] = useState({}); | ||
| const [showModal, setShowModal] = useState(false); | ||
| const [breadCrumbs, setBreadCrumbs] = useState<LinkDataType[]>([]); | ||
| const [modalTriggerRef, setModalTriggerRef] = | ||
| useState<RefObject<HTMLButtonElement> | null>(null); | ||
|  | ||
| const modalRef = useRef<HTMLDialogElement>(null); | ||
|  | ||
| const modalOpen = () => { | ||
| const openModal = () => { | ||
| setShowModal(true); | ||
| setTimeout(() => { | ||
| // Focus the dialog element after modal is set to open | ||
| modalRef?.current?.focus(); | ||
| }, 0); | ||
| }; | ||
| const closeModal = () => { | ||
| setShowModal(false); | ||
| // Focus the original modal trigger button after dialog is closed, | ||
| // otherwise, focus will be lost on the page | ||
| setTimeout(() => { | ||
| modalTriggerRef?.current?.focus(); | ||
| setModalTriggerRef(null); | ||
| }, 0); | ||
| }; | ||
|  | ||
| const addBreadCrumb = (bc) => { | ||
|  | @@ -36,14 +61,17 @@ export const ApiModalProvider = ({ children }) => { | |
|  | ||
| const value = { | ||
| setModalData, | ||
| modalOpen, | ||
| setModalTriggerRef, | ||
| modalTriggerRef, | ||
| openModal, | ||
| addBreadCrumb, | ||
| setBC | ||
| }; | ||
|  | ||
| return ( | ||
| <TypeContext.Provider value={value}> | ||
| <ApiModal | ||
| modalRef={modalRef} | ||
| data={modalData} | ||
| showModal={showModal} | ||
| close={closeModal} | ||
|  | ||
  
    
      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
    
  
  
    
              
  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.
I think I broke this, so re-fixing it.