Skip to content

Commit

Permalink
fix: Fixes alt-attribute issues for some shell bar components (#139, #…
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianKienle committed Mar 5, 2019
1 parent 0fc7ebe commit 4c83185
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 21 deletions.
12 changes: 8 additions & 4 deletions docs/src/api/_baseline.json
Expand Up @@ -976,14 +976,16 @@
"componentName": "FdShellBarGroup"
},
"FdShellBarLogo": {
"slots": {},
"slots": {
"default": "Allows you to provide a custom shell bar logo. If used, this will replace the img-element which is rendered per default."
},
"events": {},
"mixins": [],
"props": {
"src": {
"name": "src",
"description": "image source",
"required": true,
"required": false,
"types": ["String"]
},
"srcset": {
Expand Down Expand Up @@ -1156,7 +1158,9 @@
"componentName": "FdShellBarProductSwitcherItem"
},
"FdShellBarProductSwitcherItemImg": {
"slots": {},
"slots": {
"default": "Allows you to provide a custom product logo. If used, this will replace the img-element which is rendered per default."
},
"events": {},
"mixins": [],
"props": {
Expand All @@ -1165,7 +1169,7 @@
"description": "image source",
"required": false,
"types": ["String"],
"defaultValue": ""
"defaultValue": null
}
},
"componentName": "FdShellBarProductSwitcherItemImg"
Expand Down
4 changes: 3 additions & 1 deletion docs/src/layouts/DefaultLayout.vue
Expand Up @@ -7,7 +7,9 @@
src="/images/logo.png"
srcset="/images/logo.png 1x, /images/logo@2x.png 2x"
/>
<FdShellBarProduct>Fundamental Vue</FdShellBarProduct>
<FdShellBarProduct>
<FdShellBarProductTitle>Fundamental Vue</FdShellBarProductTitle>
</FdShellBarProduct>
</FdShellBarGroup>
<FdShellBarGroup position="end">
<FdShellBarActions>
Expand Down
17 changes: 7 additions & 10 deletions ui/src/components/Layout/ShellBar/ShellBarLogo.vue
@@ -1,6 +1,8 @@
<template>
<a class="fd-shellbar__logo" href="#" @click.prevent="pushLocationIfPossible">
<img :src="src" :srcset="srcset" />
<a class="fd-shellbar__logo" href="#" @click.prevent="pushLocationIfPossible" v-on="$listeners">
<slot>
<img :src="src" :srcset="srcset" v-bind="$attrs" />
</slot>
</a>
</template>

Expand All @@ -9,15 +11,10 @@ import { withTargetLocation, mixins } from "@/mixins";
export default mixins(withTargetLocation("/")).extend({
name: "FdShellBarLogo",
inheritAttrs: false,
props: {
src: {
type: String,
required: true
},
srcset: {
type: String,
default: null
}
src: String,
srcset: String
}
});
</script>
@@ -1,15 +1,18 @@
<template>
<span class="fd-product-switcher__product-icon">
<img :src="src" />
<span class="fd-product-switcher__product-icon" v-on="$listeners">
<slot>
<img :src="src" v-bind="$attrs" />
</slot>
</span>
</template>

<script lang="ts">
import Vue from "vue";
export default Vue.extend({
name: "FdShellBarProductSwitcherItemImg",
inheritAttrs: false,
props: {
src: { type: String, default: "" }
src: String
}
});
</script>
17 changes: 17 additions & 0 deletions ui/src/components/Layout/ShellBar/__tests__/ShellBarLogo.test.ts
@@ -0,0 +1,17 @@
import FdShellBarLogo from "./../ShellBarLogo.vue";
import { mount, createLocalVue } from "@vue/test-utils";

describe("ShellBarLogo", () => {
// Test for https://github.com/SAP/fundamental-vue/issues/154
it("puts alt on logo", async () => {
const localVue = createLocalVue();
const wrapper = mount({
components: { FdShellBarLogo },
template: `<FdShellBarLogo src="image.png" alt="helloWorld" />`
}, { localVue });
await localVue.nextTick();
const img = wrapper.find("img");
expect(img.exists()).toBe(true);
expect(img.attributes("alt")).toBe("helloWorld");
})
});
@@ -0,0 +1,17 @@
import FdShellBarProductSwitcherItemImg from "./../ShellBarProductSwitcherItemImg.vue";
import { mount, createLocalVue } from "@vue/test-utils";

describe("ShellBarProductSwitcherItemImg", () => {
// Test for https://github.com/SAP/fundamental-vue/issues/139
it("puts alt on logo", async () => {
const localVue = createLocalVue();
const wrapper = mount({
components: { FdShellBarProductSwitcherItemImg },
template: `<FdShellBarProductSwitcherItemImg src="image.png" alt="helloWorld" />`
}, { localVue });
await localVue.nextTick();
const img = wrapper.find("img");
expect(img.exists()).toBe(true);
expect(img.attributes("alt")).toBe("helloWorld");
})
});
6 changes: 3 additions & 3 deletions ui/src/mixins/withTargetLocation.ts
Expand Up @@ -11,13 +11,13 @@ export default (defaultTo: string | object | null = null) =>
>
},
methods: {
pushLocationIfPossible(event?: Event, onComplete?: typeof noop) {
pushLocationIfPossible(event?: Event, onComplete = noop) {
if (this.to == null || this.$router == null) {
return;
}
this.pushLocation(event, onComplete);
},
pushLocation(event?: Event, onComplete?: typeof noop) {
pushLocation(event?: Event, onComplete = noop) {
if (event) {
event.preventDefault();
event.stopPropagation();
Expand All @@ -33,7 +33,7 @@ export default (defaultTo: string | object | null = null) =>
warn(`Tried to navigate to ${to} but $router not found.`);
return;
}
$router.push(to, onComplete || noop);
$router.push(to, onComplete);
this.$emit("click", event);
}
}
Expand Down

0 comments on commit 4c83185

Please sign in to comment.