Skip to content
Snippets Groups Projects
Commit 0dc34980 authored by Glenn Fischer's avatar Glenn Fischer
Browse files

#2404: disables the move to buttom button, if conditions are met

parent 931508db
No related branches found
No related tags found
No related merge requests found
...@@ -109,13 +109,13 @@ describe('CompanionWindow', () => { ...@@ -109,13 +109,13 @@ describe('CompanionWindow', () => {
expect(companionWindow.find(Rnd).prop('default')).toEqual({ height: 201, width: 'auto' }); expect(companionWindow.find(Rnd).prop('default')).toEqual({ height: 201, width: 'auto' });
}); });
it('shows the moveToBottom button when true is passed for showMoveToBottom', () => { it('moveToBottom button is enabled when true is passed for enableMoveToBottom', () => {
companionWindow = createWrapper({ showMoveToBottom: false, updateCompanionWindow: true }); companionWindow = createWrapper({ enableMoveToBottom: true, updateCompanionWindow: true });
expect(companionWindow.find('.positionButton').length).toBe(0); expect(companionWindow.find('.positionButton[disabled=false]').length).toBe(1);
}); });
it('doesn\'t show the moveToBottom button when false is passed for showMoveToBottom', () => { it('moveToBottom button is disabled when false is passed for enableMoveToBottom', () => {
companionWindow = createWrapper({ showMoveToBottom: false, updateCompanionWindow: true }); companionWindow = createWrapper({ enableMoveToBottom: false, updateCompanionWindow: true });
expect(companionWindow.find('.positionButton').length).toBe(0); expect(companionWindow.find('.positionButton[disabled=true]').length).toBe(1);
}); });
}); });
...@@ -50,8 +50,8 @@ export class CompanionWindow extends Component { ...@@ -50,8 +50,8 @@ export class CompanionWindow extends Component {
*/ */
render() { render() {
const { const {
classes, paperClassName, id, onCloseClick, updateCompanionWindow, isDisplayed, classes, enableMoveToBottom, paperClassName, id, onCloseClick, updateCompanionWindow,
position, t, windowId, title, children, titleControls, size, showMoveToBottom, isDisplayed, position, t, windowId, title, children, titleControls, size,
} = this.props; } = this.props;
return ( return (
...@@ -96,10 +96,11 @@ export class CompanionWindow extends Component { ...@@ -96,10 +96,11 @@ export class CompanionWindow extends Component {
: ( : (
<> <>
{ {
updateCompanionWindow && showMoveToBottom && ( updateCompanionWindow && (
<MiradorMenuButton <MiradorMenuButton
aria-label={position === 'bottom' ? t('moveCompanionWindowToRight') : t('moveCompanionWindowToBottom')} aria-label={position === 'bottom' ? t('moveCompanionWindowToRight') : t('moveCompanionWindowToBottom')}
className={classes.positionButton} className={classes.positionButton}
disabled={!enableMoveToBottom}
onClick={() => { updateCompanionWindow(windowId, id, { position: position === 'bottom' ? 'right' : 'bottom' }); }} onClick={() => { updateCompanionWindow(windowId, id, { position: position === 'bottom' ? 'right' : 'bottom' }); }}
> >
<MoveIcon /> <MoveIcon />
...@@ -137,12 +138,12 @@ export class CompanionWindow extends Component { ...@@ -137,12 +138,12 @@ export class CompanionWindow extends Component {
CompanionWindow.propTypes = { CompanionWindow.propTypes = {
children: PropTypes.node, children: PropTypes.node,
classes: PropTypes.objectOf(PropTypes.string).isRequired, classes: PropTypes.objectOf(PropTypes.string).isRequired,
enableMoveToBottom: PropTypes.bool.isRequired,
id: PropTypes.string.isRequired, id: PropTypes.string.isRequired,
isDisplayed: PropTypes.bool, isDisplayed: PropTypes.bool,
onCloseClick: PropTypes.func, onCloseClick: PropTypes.func,
paperClassName: PropTypes.string, paperClassName: PropTypes.string,
position: PropTypes.string, position: PropTypes.string,
showMoveToBottom: PropTypes.bool.isRequired,
size: PropTypes.shape({ width: PropTypes.number }), size: PropTypes.shape({ width: PropTypes.number }),
t: PropTypes.func, t: PropTypes.func,
title: PropTypes.string, title: PropTypes.string,
......
...@@ -19,14 +19,14 @@ import { CompanionWindow } from '../components/CompanionWindow'; ...@@ -19,14 +19,14 @@ import { CompanionWindow } from '../components/CompanionWindow';
const mapStateToProps = (state, { id, windowId }) => { const mapStateToProps = (state, { id, windowId }) => {
const window = getWindow(state, { windowId }); const window = getWindow(state, { windowId });
const companionWindow = getCompanionWindow(state, { companionWindowId: id }); const companionWindow = getCompanionWindow(state, { companionWindowId: id });
const showMoveToBottom = !window.height || window.height > 300 || companionWindow.position !== 'right'; const enableMoveToBottom = !window.height || window.height > 300 || companionWindow.position !== 'right';
return { return {
...companionWindow, ...companionWindow,
enableMoveToBottom,
isDisplayed: (companionWindow isDisplayed: (companionWindow
&& companionWindow.content && companionWindow.content
&& companionWindow.content.length > 0), && companionWindow.content.length > 0),
showMoveToBottom,
}; };
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment