This repository was archived by the owner on Mar 4, 2020. It is now read-only.
  
  
  - 
                Notifications
    You must be signed in to change notification settings 
- Fork 51
feat(Accessibility): checkbox behavior for multiselect pattern #2264
          
     Open
      
      
            jurokapsiar
  wants to merge
  3
  commits into
  master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
acc/listbox-checkbox
  
      
      
   
  
    
  
  
  
 
  
      
    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
          
          
            3 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    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
    
  
  
    
              
        
          
  
    
      
          
            13 changes: 13 additions & 0 deletions
          
          13 
        
  docs/src/examples/components/Checkbox/Types/CheckboxListboxExample.shorthand.tsx
  
  
      
      
   
        
      
      
    
  
    
      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 | 
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { List, Checkbox, checkboxMultiselectBehavior } from '@fluentui/react' | ||
| import * as React from 'react' | ||
|  | ||
| const CheckboxLisboxExample = () => ( | ||
| <List selectable aria-multiselectable={true}> | ||
| <Checkbox label="Option 1" accessibility={checkboxMultiselectBehavior} /> | ||
| <Checkbox label="Option 2" accessibility={checkboxMultiselectBehavior} /> | ||
| <Checkbox label="Option 3" accessibility={checkboxMultiselectBehavior} /> | ||
| <Checkbox label="Option 4" accessibility={checkboxMultiselectBehavior} /> | ||
| </List> | ||
| ) | ||
|  | ||
| export default CheckboxLisboxExample | ||
  
    
      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
    
  
  
    
              
        
          
  
    
      
          
            40 changes: 40 additions & 0 deletions
          
          40 
        
  packages/accessibility/src/behaviors/Checkbox/checkboxMultiselectBehavior.ts
  
  
      
      
   
        
      
      
    
  
    
      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 | 
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import * as keyboardKey from 'keyboard-key' | ||
| import { Accessibility } from '../../types' | ||
| import { IS_FOCUSABLE_ATTRIBUTE } from '../../attributes' | ||
|  | ||
| /** | ||
| * @description | ||
| * Allows grouping of related checkboxes | ||
| * Use inside of a container with `role='listbox'` and `aria-multiselectable='true'` | ||
| * @specification | ||
| * Adds role='option'. This allows screen readers to handle the component as an option in listbox. | ||
| * Adds attribute 'aria-selected=true' based on the property 'checked'. | ||
| * Adds attribute 'aria-disabled=true' based on the property 'disabled'. | ||
| * Adds attribute 'data-is-focusable=true' to 'root' slot. | ||
| */ | ||
| const checkboxMultiselectBehavior: Accessibility<CheckboxMultiselectBehaviorProps> = props => ({ | ||
| attributes: { | ||
| root: { | ||
| 'aria-selected': !!props.checked, | ||
| 'aria-disabled': props.disabled, | ||
| role: 'option', | ||
| [IS_FOCUSABLE_ATTRIBUTE]: true, | ||
| }, | ||
| }, | ||
| keyActions: { | ||
| root: { | ||
| performClick: { | ||
| keyCombinations: [{ keyCode: keyboardKey.Spacebar }], | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
|  | ||
| export default checkboxMultiselectBehavior | ||
|  | ||
| type CheckboxMultiselectBehaviorProps = { | ||
| /** Whether or not item is checked. */ | ||
| checked: boolean | ||
| /** If the checkbox is in disabled state. */ | ||
| disabled?: boolean | ||
| } | 
  
    
      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.
Is
Listcomponent the best choice? I understand that from accessibility point it may be, but from styling point, if we decide to add some styles on the List component int he future, or if any theme has, those will be applied here as well...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.
Yeah, may be we should introduce
CheckboxGroupfor this...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 am not sure about this - the pattern is multi select listbox, so it is a combination of List and Checkbox. It would be more clear if we would introduce a "neutral" variabt of List, in case if we needed to add some styles to List