Skip to content

Commit f837016

Browse files
committed
chore: simplify conditional attributes
1 parent 8a94e95 commit f837016

File tree

7 files changed

+6
-20
lines changed

7 files changed

+6
-20
lines changed

packages/common/Label.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{context === 'image-list' ? 'mdc-image-list__label' : ''}
1111
{context === 'snackbar' ? 'mdc-snackbar__label' : ''}
1212
"
13-
{...snackbarProps}
13+
{...((context === 'snackbar') ? {role: 'status', 'aria-live': 'polite'} : {})}
1414
{...exclude($$props, ['use', 'class'])}
1515
><slot></slot></span>
1616

@@ -28,6 +28,4 @@
2828
export {className as class};
2929
3030
const context = getContext('SMUI:label:context');
31-
32-
$: snackbarProps = (context === 'snackbar') ? {role: 'status', 'aria-live': 'polite'} : {};
3331
</script>

packages/data-table/Row.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{!header ? 'mdc-data-table__row' : ''}
99
{(!header && selected) ? 'mdc-data-table__row--selected' : ''}
1010
"
11-
{...ariaSelectedProp}
11+
{...(selected !== undefined ? {'aria-selected': selected ? 'true' : 'false'} : {})}
1212
{...exclude($$props, ['use', 'class'])}
1313
><slot></slot></tr>
1414

@@ -29,8 +29,6 @@
2929
let header = getContext('SMUI:data-table:row:header');
3030
let selected = undefined;
3131
32-
$: ariaSelectedProp = selected !== undefined ? {'aria-selected': selected ? 'true' : 'false'} : {};
33-
3432
setContext('SMUI:data-table:row:getIndex', getIndex);
3533
3634
setContext('SMUI:generic:input:setChecked', setChecked);

packages/floating-label/FloatingLabel.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use:useActions={use}
1313
use:forwardEvents
1414
class="mdc-floating-label {className}"
15-
{...forProp}
15+
{...((forId || inputProps && inputProps.id) ? {'for': forId || inputProps && inputProps.id} : {})}
1616
{...exclude($$props, ['use', 'class', 'for', 'wrapped'])}
1717
><slot></slot></label>
1818
{/if}
@@ -38,8 +38,6 @@
3838
let floatingLabel;
3939
let inputProps = getContext('SMUI:generic:input:props') || {};
4040
41-
$: forProp = (forId || inputProps && inputProps.id) ? {for: forId || inputProps && inputProps.id} : {};
42-
4341
onMount(() => {
4442
floatingLabel = new MDCFloatingLabel(element);
4543
});

packages/list/Label.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use:useActions={use}
33
use:forwardEvents
44
class="mdc-list-item__text {className}"
5-
{...forProp}
5+
{...((inputProps && inputProps.id) ? {'for': inputProps && inputProps.id} : {})}
66
{...exclude($$props, ['use', 'class'])}
77
><slot></slot></label>
88

@@ -20,6 +20,4 @@
2020
export {className as class};
2121
2222
let inputProps = getContext('SMUI:generic:input:props') || {};
23-
24-
$: forProp = (inputProps && inputProps.id) ? {for: inputProps && inputProps.id} : {};
2523
</script>

packages/menu/SelectionGroup.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
const forwardEvents = forwardEventsBuilder(current_component);
2121
2222
export let use = [];
23-
let className = '';
24-
export {className as class};
2523
export let list$use = [];
2624
export let list$class = '';
2725
</script>

packages/textfield/Textfield.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
{updateInvalid}
4343
on:change
4444
on:input
45-
{...placeholderProp}
45+
{...((fullwidth && label) ? {placeholder: label} : {})}
4646
{...prefixFilter($$props, 'input$')}
4747
/>
4848
{/if}
@@ -134,8 +134,6 @@
134134
135135
$: valued = value !== uninitializedValue || files !== uninitializedValue;
136136
137-
$: placeholderProp = (fullwidth && label) ? {placeholder: label} : {};
138-
139137
$: if (textField && value !== uninitializedValue && textField.value !== value) {
140138
textField.value = value;
141139
}

packages/top-app-bar/Section.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{align === 'start' ? 'mdc-top-app-bar__section--align-start' : ''}
88
{align === 'end' ? 'mdc-top-app-bar__section--align-end' : ''}
99
"
10-
{...roleProp}
10+
{...(toolbar ? {role: 'toolbar'} : {})}
1111
{...exclude($$props, ['use', 'class', 'align', 'toolbar'])}
1212
><slot></slot></section>
1313

@@ -26,8 +26,6 @@
2626
export let align = 'start';
2727
export let toolbar = false;
2828
29-
$: roleProp = toolbar ? {role: 'toolbar'} : {};
30-
3129
setContext('SMUI:icon-button:context', toolbar ? 'top-app-bar:action' : 'top-app-bar:navigation');
3230
setContext('SMUI:button:context', toolbar ? 'top-app-bar:action' : 'top-app-bar:navigation');
3331
</script>

0 commit comments

Comments
 (0)