mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
refactor(expandable-tile): remove onMount method
- Prevent default keypress if key is a <Space> or 'Enter'
This commit is contained in:
parent
0c9fb41aff
commit
f802fdb1bd
1 changed files with 15 additions and 11 deletions
|
@ -11,7 +11,7 @@
|
||||||
export let light = false;
|
export let light = false;
|
||||||
export let style = undefined;
|
export let style = undefined;
|
||||||
|
|
||||||
import { tick, onMount } from 'svelte';
|
import { tick } from 'svelte';
|
||||||
import ChevronDown16 from 'carbon-icons-svelte/lib/ChevronDown16';
|
import ChevronDown16 from 'carbon-icons-svelte/lib/ChevronDown16';
|
||||||
import { cx, css } from '../../lib';
|
import { cx, css } from '../../lib';
|
||||||
|
|
||||||
|
@ -19,20 +19,23 @@
|
||||||
let tileContent = undefined;
|
let tileContent = undefined;
|
||||||
let aboveTheFold = undefined;
|
let aboveTheFold = undefined;
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
const tileStyle = window.getComputedStyle(tile, null);
|
|
||||||
tileMaxHeight = aboveTheFold.getBoundingClientRect().height;
|
|
||||||
tilePadding =
|
|
||||||
parseInt(tileStyle.getPropertyValue('padding-top'), 10) +
|
|
||||||
parseInt(tileStyle.getPropertyValue('padding-bottom'), 10);
|
|
||||||
});
|
|
||||||
|
|
||||||
async function setHeight() {
|
async function setHeight() {
|
||||||
await tick();
|
await tick();
|
||||||
tileMaxHeight = expanded
|
tileMaxHeight = expanded
|
||||||
? tileContent.getBoundingClientRect().height
|
? tileContent.getBoundingClientRect().height
|
||||||
: aboveTheFold.getBoundingClientRect().height;
|
: aboveTheFold.getBoundingClientRect().height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if (tile) {
|
||||||
|
const style = window.getComputedStyle(tile);
|
||||||
|
|
||||||
|
tileMaxHeight = aboveTheFold.getBoundingClientRect().height;
|
||||||
|
tilePadding =
|
||||||
|
parseInt(style.getPropertyValue('padding-top'), 10) +
|
||||||
|
parseInt(style.getPropertyValue('padding-bottom'), 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
@ -45,8 +48,9 @@
|
||||||
setHeight();
|
setHeight();
|
||||||
}}
|
}}
|
||||||
on:keypress
|
on:keypress
|
||||||
on:keypress={({ key }) => {
|
on:keypress={event => {
|
||||||
if (key === ' ' || key === 'Enter') {
|
if (event.key === ' ' || event.key === 'Enter') {
|
||||||
|
event.preventDefault();
|
||||||
expanded = !expanded;
|
expanded = !expanded;
|
||||||
setHeight();
|
setHeight();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue