mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-13 15:38:59 +00:00
* fix: replace clickable div with button improve accessibility for keyboard users * refactor: extract sidebar button to own component * refactor: button to div * fix: lint, update sidebarSection test
This commit is contained in:
parent
625b4a4ad7
commit
e39d3e52e2
3 changed files with 68 additions and 26 deletions
60
website/client/src/components/sidebarButton.vue
Normal file
60
website/client/src/components/sidebarButton.vue
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="toggle ml-auto"
|
||||||
|
role="button"
|
||||||
|
:aria-expanded="visible"
|
||||||
|
tabindex="0"
|
||||||
|
@keyup.enter="$emit('click')"
|
||||||
|
@click="$emit('click')"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
v-if="visible"
|
||||||
|
class="svg-icon"
|
||||||
|
v-html="icons.upIcon"
|
||||||
|
></span>
|
||||||
|
<span
|
||||||
|
v-else
|
||||||
|
class="svg-icon"
|
||||||
|
v-html="icons.downIcon"
|
||||||
|
></span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import '~@/assets/scss/colors.scss';
|
||||||
|
|
||||||
|
.toggle {
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
&:focus {
|
||||||
|
outline: none;
|
||||||
|
border: $purple-400 solid 1px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.svg-icon {
|
||||||
|
width: 16px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import upIcon from '@/assets/svg/up.svg';
|
||||||
|
import downIcon from '@/assets/svg/down.svg';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
visible: {
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
icons: {
|
||||||
|
upIcon,
|
||||||
|
downIcon,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
@ -22,21 +22,10 @@
|
||||||
:target="tooltipId"
|
:target="tooltipId"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<SidebarButton
|
||||||
class="section-toggle ml-auto"
|
:visible="visible"
|
||||||
@click="toggle"
|
@click="toggle"
|
||||||
>
|
/>
|
||||||
<div
|
|
||||||
v-if="visible"
|
|
||||||
class="svg-icon"
|
|
||||||
v-html="icons.upIcon"
|
|
||||||
></div>
|
|
||||||
<div
|
|
||||||
v-else
|
|
||||||
class="svg-icon"
|
|
||||||
v-html="icons.downIcon"
|
|
||||||
></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-show="visible"
|
v-show="visible"
|
||||||
|
|
@ -64,27 +53,22 @@
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.section-toggle {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.section-info {
|
.section-info {
|
||||||
cursor: help;
|
cursor: help;
|
||||||
}
|
}
|
||||||
|
|
||||||
.section-info .svg-icon,
|
.section-info .svg-icon {
|
||||||
.section-toggle .svg-icon {
|
|
||||||
width: 16px;
|
width: 16px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
import upIcon from '@/assets/svg/up.svg';
|
import SidebarButton from './sidebarButton';
|
||||||
import downIcon from '@/assets/svg/down.svg';
|
|
||||||
import informationIcon from '@/assets/svg/information.svg';
|
import informationIcon from '@/assets/svg/information.svg';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
components: { SidebarButton },
|
||||||
props: {
|
props: {
|
||||||
title: {
|
title: {
|
||||||
required: true,
|
required: true,
|
||||||
|
|
@ -101,8 +85,6 @@ export default {
|
||||||
tooltipId: uuid(),
|
tooltipId: uuid(),
|
||||||
visible: this.show,
|
visible: this.show,
|
||||||
icons: {
|
icons: {
|
||||||
upIcon,
|
|
||||||
downIcon,
|
|
||||||
information: informationIcon,
|
information: informationIcon,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,9 @@ describe('Sidebar Section', () => {
|
||||||
|
|
||||||
it('hides contents', () => {
|
it('hides contents', () => {
|
||||||
expect(wrapper.find('.section-body').element.style.display).to.not.eq('none');
|
expect(wrapper.find('.section-body').element.style.display).to.not.eq('none');
|
||||||
wrapper.find('.section-toggle').trigger('click');
|
wrapper.find('[role="button"').trigger('click');
|
||||||
expect(wrapper.find('.section-body').element.style.display).to.eq('none');
|
expect(wrapper.find('.section-body').element.style.display).to.eq('none');
|
||||||
wrapper.find('.section-toggle').trigger('click');
|
wrapper.find('[role="button"').trigger('click');
|
||||||
expect(wrapper.find('.section-body').element.style.display).to.not.eq('none');
|
expect(wrapper.find('.section-body').element.style.display).to.not.eq('none');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue