Skip to content

Commit 18b6179

Browse files
committed
Adjusts handling of the folder browser
Makes it so that the "active" item is highlighted/bolded depending on the situation. It also makes it so that keyboard navigation has a focus effect. fixes CNVS-15596 Test Plan: - Enable Better File Browsing - Go to New Files - Navigate folders using the left side navigation - The actively displayed folder should be bold. - When you use the keyboard to go up and down, a blue background should be there. - Move a file using the Move dialog - The currently selected folder should have a blue background. Change-Id: I260750b41a41d39f925b33e8b84c5b0984d0d7a2 Reviewed-on: https://gerrit.instructure.com/43249 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Ryan Shaw <ryan@instructure.com> Product-Review: Ryan Shaw <ryan@instructure.com> QA-Review: Jahnavi Yetukuri <jyetukuri@instructure.com>
1 parent 4fffb25 commit 18b6179

7 files changed

Lines changed: 60 additions & 9 deletions

File tree

app/coffeescripts/react_files/components/FolderTree.coffee

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ define [
1212
rootFoldersToShow: React.PropTypes.arrayOf(customPropTypes.folder).isRequired
1313
rootTillCurrentFolder: React.PropTypes.arrayOf(customPropTypes.folder)
1414

15-
mixins: [Router.Navigation]
15+
mixins: [Router.Navigation, Router.ActiveState]
1616

1717
componentDidMount: ->
1818
new FileBrowserView({
@@ -21,6 +21,8 @@ define [
2121
onClick: @onClick
2222
dndOptions: @props.dndOptions
2323
href: @hrefFor
24+
focusStyleClass: @focusStyleClass
25+
selectedStyleClass: @selectedStyleClass
2426
}).render().$el.appendTo(@refs.FolderTreeHolder.getDOMNode())
2527
@expandTillCurrentFolder(@props)
2628

@@ -31,13 +33,20 @@ define [
3133

3234
onClick: (event, folder) ->
3335
event.preventDefault()
36+
$(@refs.FolderTreeHolder.getDOMNode()).find('.' + @focusStyleClass).each( (key, value) => $(value).removeClass(@focusStyleClass))
37+
$(@refs.FolderTreeHolder.getDOMNode()).find('.' + @selectedStyleClass).each( (key, value) => $(value).removeClass(@selectedStyleClass))
3438
@transitionTo (if folder.urlPath() then 'folder' else 'rootFolder'), splat: folder.urlPath()
3539

3640

3741
hrefFor: (folder) ->
3842
@makeHref (if folder.urlPath() then 'folder' else 'rootFolder'), splat: folder.urlPath()
3943

4044

45+
46+
focusStyleClass: 'FolderTree__folderItem--focused'
47+
selectedStyleClass: 'FolderTree__folderItem--selected'
48+
49+
4150
expandTillCurrentFolder: (props) ->
4251
expandFolder = (folderIndex) ->
4352
return unless folder = props.rootTillCurrentFolder?[folderIndex]

app/coffeescripts/react_files/components/MoveDialog.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ define [
3333
onlyShowFolders: true,
3434
rootFoldersToShow: @props.rootFoldersToShow
3535
onClick: @onSelectFolder
36+
focusStyleClass: 'MoveDialog__folderItem--focused'
37+
selectedStyleClass: 'MoveDialog__folderItem--selected'
3638
}).render().$el.appendTo(@refs.FolderTreeHolder.getDOMNode()).find(':tabbable:first').focus();
3739

3840
onSelectFolder: (event, folder) ->

app/coffeescripts/views/FileBrowserView.coffee

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ define [
1818
@optionProperty 'onClick'
1919
@optionProperty 'dndOptions'
2020
@optionProperty 'href'
21+
@optionProperty 'focusStyleClass'
22+
@optionProperty 'selectedStyleClass'
2123

2224
# Handle keyboard events for accessibility.
2325
events:
@@ -58,7 +60,7 @@ define [
5860
contextTypeAndId = splitAssetString(ENV.context_asset_string || '')
5961
if contextTypeAndId && contextTypeAndId.length == 2 && (contextTypeAndId[0] == 'courses' || contextTypeAndId[0] == 'groups')
6062
contextFiles = new Folder({contentTypes: @contentTypes})
61-
contextFiles.set 'custom_name', if contextTypeAndId[0] is 'courses' then I18n.t('course_files', 'Course files') else I18n.t('group_files', 'Group files')
63+
contextFiles.set 'custom_name', if contextTypeAndId[0] is 'courses' then I18n.t('course_files', 'Course files') else I18n.t('group_files', 'Group files')
6264
contextFiles.url = "/api/v1/#{contextTypeAndId[0]}/#{contextTypeAndId[1]}/folders/root"
6365
contextFiles.fetch()
6466

@@ -81,15 +83,17 @@ define [
8183
onClick: @onClick
8284
dndOptions: @dndOptions
8385
href: @href
86+
selectedStyleClass: @selectedStyleClass
8487
}).$el.appendTo(@$folderTree)
8588
super
8689

8790
# Set the focus from one tree item to another.
8891
setFocus: ($to, $from) ->
8992
if not $to?.length or $from?.is? $to
9093
return
91-
@$folderTree.find('[role=treeitem]').not($to).attr 'aria-selected', false
94+
@$folderTree.find('[role=treeitem]').not($to).attr('aria-selected', false).removeClass(@focusStyleClass)
9295
$to.attr 'aria-selected', true
96+
$to.addClass(@focusStyleClass)
9397
toId = $to.attr 'id'
9498
if not toId
9599
toId = _.uniqueId 'treenode-'
@@ -176,6 +180,7 @@ define [
176180
else
177181
@setFocus $current.parent().closest('[role=treeitem]'), $current
178182

179-
activateCurrent: ($current) -> $current.find('a:first').click()
183+
activateCurrent: ($current) ->
184+
$current.find('a:first').trigger('selectItem')
180185

181186
ariaPropIsTrue: ($e, attrib) -> $e.attr(attrib)?.toLowerCase?() is 'true'

app/coffeescripts/views/FolderTreeView.coffee

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ define [
1212
class FolderTreeView extends Backbone.View
1313

1414
tagName: 'li'
15-
15+
1616
@optionProperty 'nestingLevel'
1717
@optionProperty 'onlyShowFolders'
1818
@optionProperty 'onClick'
1919
@optionProperty 'dndOptions'
2020
@optionProperty 'href'
21+
@optionProperty 'focusStyleClass'
22+
@optionProperty 'selectedStyleClass'
2123

22-
2324
defaults:
2425
nestingLevel: 1
2526

@@ -31,6 +32,7 @@ define [
3132

3233
events:
3334
'click .folderLabel': 'toggle'
35+
'selectItem .folderLabel': 'selectItem'
3436

3537
initialize: ->
3638
@tagId = _.uniqueId 'treenode-'
@@ -54,13 +56,21 @@ define [
5456
@model.toggle({onlyShowFolders: @onlyShowFolders})
5557
@$el.attr(@attributes())
5658

59+
selectItem: (event) ->
60+
$span = $(event.target).find('span')
61+
$span.trigger('click')
62+
5763
title_text: ->
5864
@model.get('custom_name') || @model.get('name')
59-
65+
6066
renderSelf: ->
6167
@$el.attr @attributes()
6268
@$label ||= do =>
63-
@$labelInner = $('<span>').click (event) => @onClick?(event, @model)
69+
@$labelInner = $('<span>').click (event) =>
70+
if (@selectedStyleClass)
71+
$('.' + _this.selectedStyleClass).each((key, element) => $(element).removeClass(@selectedStyleClass))
72+
$(event.target).addClass(@selectedStyleClass)
73+
@onClick?(event, @model)
6474

6575
$label = $("""
6676
<a
@@ -92,6 +102,9 @@ define [
92102
.toggleClass('expanded', !!@model.isExpanded)
93103
.toggleClass('loading after', !!@model.isExpanding)
94104

105+
# Let's this work well with file browsers like New Files
106+
if (@selectedStyleClass)
107+
@$label.toggleClass(@selectedStyleClass, window.location.pathname is @href?(@model))
95108

96109
renderContents: ->
97110
if @model.isExpanded
@@ -106,6 +119,8 @@ define [
106119
onClick: @onClick
107120
dndOptions: @dndOptions
108121
href: @href
122+
focusStyleClass: @focusStyleClass
123+
selectedStyleClass: @selectedStyleClass
109124
tagName: 'li'
110125
className: 'folders'
111126
template: collectionTemplate
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.FolderTree__folderItem--selected {
2+
font-weight: bold;
3+
}
4+
5+
.FolderTree__folderItem--focused {
6+
& > .folderLabel {
7+
background-color: $base-list-item-background--hover;
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.MoveDialog__folderItem--selected {
2+
background-color: $base-list-item-background--selected
3+
}
4+
5+
.MoveDialog__folderItem--focused {
6+
& > .folderLabel {
7+
background-color: $base-list-item-background--hover
8+
}
9+
}

app/stylesheets/pages/react_files/compiler-react_files.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
// Styles for specific React Components
77
@import "./FilePreview";
88
@import "./RestrictedDialogForm";
9-
@import "./UploadDropZone";
9+
@import "./UploadDropZone";
10+
@import "./MoveDialog";
11+
@import "./FolderTree";

0 commit comments

Comments
 (0)