Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
refactor: review nits + add autofocus to drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuf-musleh committed Jan 8, 2024
1 parent 7a30b93 commit 27f09f5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
32 changes: 18 additions & 14 deletions src/library-authoring/author-library/LibraryAuthoringPage.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react-hooks/exhaustive-deps */
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useRef } from 'react';
import PropTypes from 'prop-types';
import {
ActionRow,
Expand Down Expand Up @@ -486,6 +486,8 @@ const LibraryAuthoringPageHeader = connect(
)(injectIntl(LibraryAuthoringPageHeaderBase));

const ContentTagsDrawer = ({ openContentTagsDrawer, setOpenContentTagsDrawer }) => {
const iFrameRef = useRef();

if (openContentTagsDrawer) {
document.body.classList.add('drawer-open');
} else {
Expand Down Expand Up @@ -519,26 +521,28 @@ const ContentTagsDrawer = ({ openContentTagsDrawer, setOpenContentTagsDrawer })
};
}, []);

useEffect(() => {
if (openContentTagsDrawer && iFrameRef.current) {
iFrameRef.current.focus();
}
}, [openContentTagsDrawer]);

// TODO: The use of an iframe in the implementation will likely change
const renderIFrame = () => (
openContentTagsDrawer
? (
<iframe
title="manage-tags-drawer"
src={`${getConfig().COURSE_AUTHORING_MFE_BASE_URL}/tagging/components/widget/${openContentTagsDrawer}`}
frameBorder="0"
style={{ width: '100%', height: '100%' }}
/>
)
: null
<iframe
ref={iFrameRef}
title="manage-tags-drawer"
className="w-100 h-100 border-0"
src={`${getConfig().COURSE_AUTHORING_MFE_BASE_URL}/tagging/components/widget/${openContentTagsDrawer}`}
/>
);

return (
return openContentTagsDrawer && (
<>
<div id="manage-tags-drawer" className={`drawer ${openContentTagsDrawer ? 'd-block' : ''}`}>
<div id="manage-tags-drawer" className="drawer">
{ renderIFrame() }
</div>
<div className={`drawer-cover ${openContentTagsDrawer ? 'd-block' : ''}`} />
<div className="drawer-cover" />
</>
);
};
Expand Down
3 changes: 1 addition & 2 deletions src/library-authoring/author-library/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
.drawer-cover {
z-index: 1000;

display: none;
position: fixed;
top: 0;
left: 0;
Expand All @@ -51,7 +50,6 @@
.drawer {
z-index: 10000;

display: none;
position: fixed;
top: 0;
right: 0;
Expand All @@ -60,6 +58,7 @@
background-color: $light-200;
}

// This is to prevent the darkened part of the page from being scrollable
body.drawer-open {
overflow: hidden;
}
2 changes: 1 addition & 1 deletion src/library-authoring/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ body {

&:hover {
color: white;
background-color: #0A3055;
background-color: $primary;
}
}

0 comments on commit 27f09f5

Please sign in to comment.