Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 78d55cd

Browse files
authored
fix(fab): allow reactive switching between basic and extended style (#533)
* fix(fab): update README.md * fix(fab): make it possible to switching between extended and basic fab reactive possible defect: using style `display: none` for label in basic fab * test(fab): update snapshots
1 parent 06b1a34 commit 78d55cd

3 files changed

Lines changed: 36 additions & 51 deletions

File tree

components/fab/Fab.vue

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
v-on="$listeners"
88
>
99
<slot name="icon" />
10-
<div
11-
v-if="extended"
10+
<span
11+
v-show="extended"
1212
class="mdc-fab__label"
1313
>
1414
<slot />
15-
</div>
15+
</span>
1616
<slot name="trailingIcon" />
1717
</button>
1818
<a
@@ -24,12 +24,12 @@
2424
v-on="$listeners"
2525
>
2626
<slot name="icon" />
27-
<div
28-
v-if="extended"
27+
<span
28+
v-show="extended"
2929
class="mdc-fab__label"
3030
>
3131
<slot />
32-
</div>
32+
</span>
3333
<slot name="trailingIcon" />
3434
</a>
3535
</template>
@@ -93,7 +93,8 @@ export default {
9393
this.slotObserver = new MutationObserver(() => this.updateSlot())
9494
this.slotObserver.observe(this.$el, {
9595
childList: true,
96-
subtree: true
96+
subtree: true,
97+
characterData: true
9798
})
9899
if (this.ripple) this.mdcRipple = MDCRipple.attachTo(this.$el)
99100
},
@@ -123,15 +124,12 @@ export default {
123124
}
124125
},
125126
reInstantiateRipple () {
127+
if (this.mdcRipple instanceof MDCRipple) {
128+
this.mdcRipple.destroy()
129+
}
126130
if (this.ripple) {
127-
if (this.mdcRipple) {
128-
this.mdcRipple.destroy()
129-
}
130131
MDCRipple.attachTo(this.$el)
131132
} else {
132-
if (this.mdcRipple) {
133-
this.mdcRipple.destroy()
134-
}
135133
this.mdcRipple = undefined
136134
}
137135
}

components/fab/README.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,28 @@
22

33
### Markup
44

5+
#### Basic Usage
6+
7+
```html
8+
<m-fab aria-label="Add">
9+
<m-icon icon="add" slot="icon"></m-icon>
10+
</m-fab>
11+
```
12+
13+
#### Extended FAB
14+
515
```html
6-
<m-fab aria-label="Favorite">
7-
<m-fab-icon class="material-icons">favorite</m-fab-icon>
16+
<m-fab aria-label="Create">
17+
<m-icon icon="add" slot="icon"></m-icon>
18+
Create
819
</m-fab>
920
```
1021

11-
### Extended FAB
22+
#### Using Font Awesome
1223

1324
```html
14-
<m-fab>
15-
<m-fab-icon class="material-icons">add</m-fab-icon>
16-
<m-fab-label>Create</m-fab-label>
25+
<m-fab aria-label="Take photo">
26+
<i class="fas fa-camera" slot="icon"></i>
1727
</m-fab>
1828
```
1929

@@ -34,6 +44,8 @@ Events and attributes are mapped to the inner button element.
3444
| Slot | Description |
3545
|------|-------------|
3646
| default | fab content |
47+
| icon | leading icon in extended fab |
48+
| trailingIcon | trailing icon in extended fab |
3749

3850
### Additional Information
3951

@@ -57,16 +69,10 @@ Developers must position `<m-fab>` as needed within their application’s design
5769
}
5870
</style>
5971
<m-fab class="app-fab--absolute" aria-label="Favorite">
60-
<m-fab-icon class="material-icons">favorite</m-fab-icon>
72+
<m-icon icon="favorite" slot="icon"></m-icon>
6173
</m-fab>
6274
```
6375

64-
### Slots
65-
66-
| Slot | Description |
67-
|------|-------------|
68-
| default | label content |
69-
7076
## Reference
7177

7278
- https://github.com/material-components/material-components-web/tree/master/packages/mdc-fab
Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,13 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Fab should render as absolute right 1`] = `
4-
<button class="mdc-fab mdc-fab--absolute-right">
5-
<!----> </button>
6-
`;
3+
exports[`Fab should render as absolute right 1`] = `<button class="mdc-fab mdc-fab--absolute-right"> <span class="mdc-fab__label" style="display: none;"></span> </button>`;
74

8-
exports[`Fab should render as exited 1`] = `
9-
<button class="mdc-fab mdc-fab--exited">
10-
<!----> </button>
11-
`;
5+
exports[`Fab should render as exited 1`] = `<button class="mdc-fab mdc-fab--exited"> <span class="mdc-fab__label" style="display: none;"></span> </button>`;
126

13-
exports[`Fab should render as extended 1`] = `
14-
<button class="mdc-fab mdc-fab--extended">
15-
<div class="mdc-fab__label">create</div>
16-
</button>
17-
`;
7+
exports[`Fab should render as extended 1`] = `<button class="mdc-fab mdc-fab--extended"> <span class="mdc-fab__label" style="">create</span> </button>`;
188

19-
exports[`Fab should render as mini 1`] = `
20-
<button class="mdc-fab mdc-fab--mini">
21-
<!----> </button>
22-
`;
9+
exports[`Fab should render as mini 1`] = `<button class="mdc-fab mdc-fab--mini"> <span class="mdc-fab__label" style="display: none;"></span> </button>`;
2310

24-
exports[`Fab should render with no prop 1`] = `
25-
<button class="mdc-fab">
26-
<!----> </button>
27-
`;
11+
exports[`Fab should render with no prop 1`] = `<button class="mdc-fab"> <span class="mdc-fab__label" style="display: none;"></span> </button>`;
2812

29-
exports[`Fab should render without ripple 1`] = `
30-
<button class="mdc-fab">
31-
<!----> </button>
32-
`;
13+
exports[`Fab should render without ripple 1`] = `<button class="mdc-fab"> <span class="mdc-fab__label" style="display: none;"></span> </button>`;

0 commit comments

Comments
 (0)