The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December. Read our blog post for more info about this change.
Found this content helpful? Log in or sign up to leave a like!
Hello,
A recent Canvas update left a lot of institutions without the ability to add additional resources to their Canvas Global Navigation. Previous discussions include:
Custom JavaScript/CSS Changes Adding custom menu items https://community.canvaslms.com/ideas/4034-custom-menu-items-for-new-ui
Source Code: https://github.com/robert-carroll/ccsd-canvas/tree/main/global-nav-custom-tray
This JavaScript will spawn and style (with CSS) DOM elements that mimic the Canvas global navigation tray, with animated easing for opening and closing the tray, and other interactions with the global navigation.
To create a tray that only shows up for certain roles, wrap the tray in an if condition that checks for role.
2 role example
if(ENV.current_user_roles.indexOf('teacher') >= 0 || ENV.current_user_roles.indexOf('admin') >= 0) {
// tray source here
}1 role example
if(ENV.current_user_roles.indexOf('student') >= 0){
$(document).ready(function() {
///* set tray title, icon, links and footer here *///
///* for user role based conditions see README *///
var title = 'Resources',
svg = '/pin-gregor-cresnar.svg',
trayLinks = [
{ href: 'http://www.example.com/your-library', title: 'Library', desc:'Optional text description' },
{ href: 'http://www.google.com', title: 'Google' },
{ href: 'http://www.example.com/help-desk', title: 'Help Desk', desc:'Optional text description' }
],
footer = 'Optional footer text, put whatever you want here, or leave it blank.';
///* options are above for convenience, continue if you like *///
// tray source here
});
}
You can also create a tray that will appear for all users, but provide links (or even the tray name, icon, and footer), specific to the user role.
var title = 'Resources',
svg = '/pin-gregor-cresnar.svg',
// default links for all users
trayLinks = [
{ href: 'http://www.example.com/your-library', title: 'Library', desc:'Optional text description' },
{ href: 'http://www.google.com', title: 'Google' },
{ href: 'http://www.example.com/help-desk', title: 'Help Desk', desc:'Optional text description' }
],
footer = 'Default footer for all users';
// these links are appended to the tray by user role
if(ENV.current_user_roles.indexOf('teacher') >= 0 || ENV.current_user_roles.indexOf('admin') >= 0){
trayLinks.push({ href: 'http://www.example.com/your-library', title: 'Teacher Library', desc:'Optional text description' })
trayLinks.push({ href: 'http://www.google.com', title: 'Google' })
footer = 'Teacher/Admin Footer overwrites default';
} else if (ENV.current_user_roles.indexOf('student') >= 0) {
trayLinks.push({ href: 'http://www.example.com/your-library', title: 'Student Library', desc:'Optional text description' })
trayLinks.push({ href: 'http://www.google.com', title: 'Google' })
footer = 'Student Footer overwrites default';
}Pin by Gregor Cresnar from The Noun Project
https://creativecommons.org/licenses/by/3.0/
Solved! Go to Solution.
Hi, @chriscas
Oh my God, how embarrassing. That's what I get for jumping into dev mode without having completed a getting-started guide. Well, I suppose my idiocy is good news. I really appreciate your help. Was desperately looking for a cache clear or something.
Best,
Justine
CSS can't really access the DOM, it just paints it. To run conditions for the page we need JavaScript.
hi, it looks like a recent code deploy may have changed the spacing above and below the icon. I haven't found where to adjust this is in the custom CSS, can you point me in the right direction, Robert Carroll?
I'm about to head about of town for the week, I can check I get back.
@JACOBSEN_C and @leon_huang
Triaging my week away, is the size of the icon the only issue you are experiencing right now?
Looks like it. The size and spacing to it all.
I have the same problem, as it seems to be expanding the pixels or something and creating a scrollbar on the side of the Nav. It kicked my icon and text down lower. When I remove the JS it is back to normal.
edit: The easiest fix for this is to set the size of the SVG in the SVG element.
ex: I've set height and width to 26px, and this will be the size of the icon and spacing within the global nav.
While there is no need to update the code to fix this, I found a couple updates for Accessibility in Canvas commits that I've implemented and are available in the updated repo. set global nav tray link to read as button and hr role=presentation l… · robert-carroll/ccsd-canvas@...
@JACOBSEN_C , @mkollman , @leon_huang
Please let me know if this resolves the issue for you.
thanks, but the .svg thing is eluding me. I have a place in themes to upload .css and .js. I apologize for my ignorance, but where does the .svg file go, or does that bit of code go into the .js?
The JS file is pointing to an SVG file for the icon on Line 13
ccsd-canvas/global-nav-custom-tray.js at master · robert-carroll/ccsd-canvas · GitHub
Are you hosting that image or pointing to something public hosted?
Clint, can you test this real quick and I'll try to come up with something.
After line 86 (or the equivalent), add height and width, to override the SVG default.
L86 svg.setAttribute('id', svg_id);
L87+ svg.setAttribute('height', '26px');
L88+ svg.setAttribute('width', '26px');
Not at lines 86-88 but it seems to almost do the trick after line 74 only adding...
svg.setAttribute('height', '26px');
svg.setAttribute('width', '26px');Line 74 is...
svg.setAttribute('id', svg_id);... still, though, it seems unstable when returning to the Canvas dashboard from somewhere else in the instance. The entire theme is lost but comes back after refreshing the page.
And after a few more minutes the theme seems to stabilize....
Takes a minute for Canvas to deliver the new file to the user.
I've updated the code, with a line in the settings to override the svg_size
ccsd-canvas/global-nav-custom-tray.js at master · robert-carroll/ccsd-canvas · GitHub
You will need to update the whole file as I made other changes.
Let me know if that works for you.
Clint, have you been able to try this yet?
Anyone else?
Nope.. little pressed on time. Soon though, thnx!
Just slipping it verbatim into our test instance doesn't produce a tray when clicked.
Is the CSS file uploaded to test?
Yes. I didnt see that anything changed in the CSS.
The CSS hasn't changed. From your screenshot a tray is being opened, it's just not styled, which seems to point to the CSS not being uploaded.
CSS is uploaded. Still no tray...
I just tossed this into our beta environment with the Instructure icon you're using, didn't have any issues.
...but that sounds too much like 'works on my machine' for me...
@mjennings and I once did some hacking on kennethware over Zoom, do you want to try troubleshooting this together? I don't actually have a zoom account but I'm open to trying something to get it working faster for you.
Works now, but we're back to the odd spacing. Is the JS picking up the 26px from your svg file? I'm back to not being able to edit the attribute and preserving the icon...
Have you tried updating the whole file, and adding your custom links back? I made multiple changes, most significantly L#15 and L#93 that cover the SVG size, and allow you to override the size if the file is one you cannot edit. I also made several changes to improve Accessibility after noticing changes in Canvas, so I recommend updating the whole thing.
Ah! Gotcha! Thank tons!
Fantastic. You're welcome. Thanks for your patience!
Setting the size of the graphic worked for me. No issues and everyone is happy. THANKS!!!!
Same here. Thanks Robert.
In my case I needed to place an external link into the main nav that opened in a new tab so I did this:
function LibraryMainNav() {
const checkIfNull = async selector => {
while (document.querySelector(selector) === null) {
await new Promise(resolve => requestAnimationFrame(resolve));
}
return document.querySelector(selector);
};
checkIfNull("#menu").then(() => {
const mainMenu = document.querySelector('#menu.ic-app-header__menu-list');
let temp = new DocumentFragment();
let liNode = document.createElement('li');
liNode.setAttribute('class','menu-item ic-app-header__menu-list-item');
temp.appendChild(liNode);
const liNodeApp = temp.querySelector('.menu-item.ic-app-header__menu-list-item');
liNodeApp.innerHTML=`
<a id="global_nav_library_link" class="ic-app-header__menu-list-link" href="https://some.link" target="_blank">
<div class="menu-item-icon-container">
<span aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" class="ic-icon-svg ic-icon-svg--inbox" version="1.1" x="0" y="0" viewBox="0 0 500 500" enable-background="new 0 0 280 280" xml:space="preserve"><path fill="currentColor" d="M459.91 192.02c-.7 0-1.39.02-2.06.05-49.8 2.84-140.51 13-201.84 47.57-61.33-34.57-152.05-44.73-201.84-47.57-.67-.04-1.36-.05-2.06-.05C31.71 192.01 0 206.36 0 242.22v178.05c0 26.69 21.25 48.7 48.34 50.12 34.41 1.81 120.56 9.08 177 37.47 4.68 2.37 9.66 3.5 14.66 3.84v.27h2.27c.09 0 .18.03.26.03h26.94c.09 0 .18-.03.26-.03H272v-.27c5-.34 9.98-1.48 14.66-3.84 56.44-28.39 142.59-35.65 177-37.47 27.09-1.42 48.34-23.44 48.34-50.12V242.22c0-35.86-31.71-50.2-52.09-50.2zM240 479.35c-.09-.04-.18-.02-.28-.07-59.59-29.97-144.43-38.45-189.7-40.84-10.1-.53-18.02-8.51-18.02-18.17V242.22c0-6.05 1.77-10 5.93-13.2 4.47-3.44 10.47-5.01 14.4-5.01 37.01 2.11 129.27 10.58 187.67 43.36v211.98zm240-59.08c0 9.66-7.92 17.64-18.03 18.17-45.27 2.38-130.11 10.86-189.76 40.87-.07.04-.14.02-.22.05V267.37c58.39-32.79 150.66-41.25 187.51-43.35l.39-.01c.2 0 20.09.49 20.09 18.21v178.05zM256 191.99c53.02 0 96-42.98 96-95.99S309.02 0 256 0s-96 42.98-96 95.99 42.98 96 96 96zM256 32c35.29 0 64 28.71 64 64s-28.71 64-64 64-64-28.71-64-64 28.71-64 64-64z"></path></svg></span>
</div>
<div class="menu-item__text">
Library
</div>
</a>
`;
mainMenu.appendChild(temp);
});
}
may I applie this to Robs Global Nav Custom Tray code? I need to list bunch of listed links for students to be able to open them in a new tab/ window
Is there a trick to change the color of these custom nav icons and text?
It depends on the image type. If you are using a .png: No. If you are utilizing a SVG:yes
path fill="currentColor"you can set color to any HTML5 color name, HEX, RGB, etc.
Thanks, they are svg's - icons from instructure's library here - but this doesn't seem to work.
(´。_。`)…Sorry been a little backed up here. If you are embedding the SVGs as images like they do in the link you sent they cannot be manipulated in the CSS or JS. if you go the actual SVG(like this clock one) and embed you can manipulate.
```
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2000 2000" version="1.1" height="50pt" width="50pt">
<path fill="red" d="M960 0c-82.96 0-163.12 11.68-240 31.6v165.28C795.84 173.04 876.4 160 960 160c441.2 0 800 358.88 800 800s-358.8 800-800 800c-441.12 0-800-358.88-800-800 0-223.04 92.16-424.48 240-569.52V640h160V160H80v160h166.32C93.6 490 0 714 0 960c0 529.36 430.72 960 960 960 529.36 0 960-430.64 960-960S1489.36 0 960 0zm-80 400v560c0 21.2 8.4 41.6 23.44 56.64l320 320 113.12-113.2L1040 926.88V400H880z" stroke="none" stroke-width="1" fill-rule="evenodd"/>
</svg>```
Clint, try commenting out line 92, that removes the fill attribute.
ccsd-canvas/global-nav-custom-tray.js at master · robert-carroll/ccsd-canvas · GitHub
Sorry I didn't notice this sooner.
Hi all,
I would like to add svg symbol definition code. Could you help to point me the right direction?
We have two extra buttons one to a course and the second with a tray full of links.
I would like to add one more, but would like to use an icon which isn't on Canvas list. I have managed to use it with the version listed by Douglas Brace from 23/04/19, but no with Roberts version.
Any support appreciated, thank you
I'm having trouble understanding what you're trying to do?
You want to change the icon or add a second, third, nth menu?
my apologies for not being clear.
what I would like to achieve to use your code and add our custom icon. e.g.
$(document).ready(function() {
addMenuItem3('Accessibility', 'https://activatelearningonline.test.instructure.com/courses/4989','<svg xmlns="http://www.w3.org/2000/svg" class="ic-icon-svg menu-item__icon svg-icon-lifepreserver" version="1.1" x="0" y="0" viewBox="0 0 230 230 " enable-background="new 0 0 230 230"xml:space="preserve" fill="transparent" stroke="white" stroke-width="2"> <path d="M 152.50,90.12 C 146.00,92.00 136.50,94.38 131.50,95.25 122.75,96.75 121.88,96.62 104.00,92.12 93.88,89.62 84.38,87.50 82.88,87.50 78.75,87.50 75.50,93.00 77.25,96.88 78.38,99.25 81.12,100.62 91.50,103.75 116.88,111.38 114.38,110.00 114.75,117.00 115.38,127.25 112.63,138.50 104.25,159.50 99.88,170.62 96.25,180.12 96.25,180.88 96.25,181.50 97.63,183.38 99.25,184.88 101.63,187.12 103.12,187.62 105.62,187.00 108.50,186.25 110.25,183.50 116.63,170.00 120.88,161.12 124.62,153.75 125.00,153.75 125.38,153.75 128.75,160.62 132.50,168.88 140.25,186.12 143.12,189.12 148.62,186.12 153.50,183.38 153.25,179.62 147.12,165.00 139.00,145.75 135.25,133.12 134.38,122.25 133.38,110.62 133.00,111.00 153.75,105.00 171.12,100.00 175.75,95.87 171.00,89.75 168.25,86.38 164.75,86.38 152.50,90.12 Z M 115.50,65.50 C 112.00,69.00 111.25,70.75 111.25,75.00 111.25,79.25 112.00,81.00 115.50,84.50 119.00,88.00 120.75,88.75 125.00,88.75 129.25,88.75 131.00,88.00 134.50,84.50 138.00,81.00 138.75,79.25 138.75,75.00 138.75,70.75 138.00,69.00 134.50,65.50 131.00,62.00 129.25,61.25 125.00,61.25 120.75,61.25 119.00,62.00 115.50,65.50 Z M 101.12,27.50 C 82.50,32.12 66.12,41.50 53.00,55.25 34.12,74.88 25.00,97.62 25.00,125.00 25.00,152.38 34.12,175.12 53.00,194.75 85.75,229.00 139.25,235.12 179.50,209.38 208.00,191.12 225.00,159.62 225.00,125.00 225.00,77.87 194.00,38.37 148.25,27.50 134.88,24.25 114.25,24.25 101.12,27.50 Z M 148.12,35.75 C 180.12,44.12 205.62,69.75 214.50,102.50 217.50,113.50 217.50,136.38 214.50,147.50 205.88,179.88 179.88,205.88 147.50,214.50 136.50,217.50 113.50,217.50 102.50,214.50 70.25,206.00 44.13,179.88 35.50,147.50 32.50,136.38 32.50,113.50 35.50,102.50 45.62,65.62 74.88,39.50 113.12,33.25 119.75,32.25 140.38,33.62 148.12,35.75 Z" /></svg>');
});
or using the code presented by Douglas Brace from 23/04/19 in this thread but would need to add the custom tray
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in