Skip to content

Commit 397fa16

Browse files
committed
Show either accept all or accept selected depending on user choices
1 parent f55dac2 commit 397fa16

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

README.MD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,11 @@ const props = {
151151

152152
/**
153153
* All the button labels and aria-label content.
154+
155+
Note that either acceptAllLabel or acceptSelectedLabel will appear, depending on whether the user has selected all or only some cookie choices in the configuration dialogue.
154156
**/
155-
acceptLabel: 'Confirm all',
157+
acceptAllLabel: 'Accept all',
158+
acceptSelectedLabel: 'Accept selected',
156159
rejectLabel: 'Reject all',
157160
settingsLabel: 'Preferences',
158161
closeLabel: 'Close window',

src/lib/Banner.svelte

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
/**
3838
* @type {string|undefined|null}
3939
*/
40-
export let acceptLabel = 'Accept all'
40+
export let acceptAllLabel = 'Accept all'
41+
export let acceptSelectedLabel = 'Accept selected'
4142
export let rejectLabel = 'Reject all'
4243
export let settingsLabel = 'Cookie settings'
4344
export let closeLabel = 'Close settings'
4445
export let editLabel = 'Edit cookie settings'
45-
export let saveLabel = 'Accept selected'
4646
4747
/**
4848
* Whether to show the cookie banner if the user has not yet accepted or rejected your choices.
@@ -109,10 +109,7 @@
109109
return result
110110
}, {})
111111
112-
$: allCookieChoices = choicesArr.reduce((result, item) => {
113-
result[item.id] = true
114-
return result
115-
}, {})
112+
$: hasSelectedAllCookieTypes = Object.values(cookieChoices).every(value => value === true)
116113
117114
export function show () {
118115
shown = visible
@@ -179,15 +176,10 @@
179176
execute(necessaryCookieChoices)
180177
}
181178
182-
function choose () {
179+
function accept () {
183180
setCookie(cookieChoices)
184181
execute(cookieChoices)
185182
}
186-
187-
function accept () {
188-
setCookie(allCookieChoices)
189-
execute(allCookieChoices)
190-
}
191183
</script>
192184

193185
{#if showEditIcon}
@@ -239,15 +231,6 @@
239231
on:click={() => { settingsShown = true } }>
240232
{settingsLabel}
241233
</button>
242-
<button
243-
type="submit"
244-
class="cookieConsent__Button"
245-
part="button button--choose"
246-
on:click={choose}
247-
aria-label={saveLabel}
248-
>
249-
{saveLabel}
250-
</button>
251234
{#if canRejectCookies}
252235
<button
253236
type="submit"
@@ -264,9 +247,9 @@
264247
class="cookieConsent__Button cookieConsent__Button--Accept"
265248
part="button button--accept"
266249
on:click={accept}
267-
aria-label={acceptLabel}
250+
aria-label={hasSelectedAllCookieTypes ? acceptAllLabel : acceptSelectedLabel}
268251
>
269-
{acceptLabel}
252+
{hasSelectedAllCookieTypes ? acceptAllLabel : acceptSelectedLabel}
270253
</button>
271254
</div>
272255
</div>

0 commit comments

Comments
 (0)