Skip to content

Commit 9ff8429

Browse files
Expose segmenter for countType: "words"
Unless the (deprecated) `maxwords` option is used
1 parent e36b9ac commit 9ff8429

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

packages/govuk-frontend/src/govuk/components/character-count/character-count.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ export class CharacterCount extends ConfigurableComponent {
131131
locale: closestAttributeValue(this.$root, 'lang')
132132
})
133133

134-
if (this.config.countType === 'characters') {
134+
if (
135+
this.config.countType === 'characters' ||
136+
(this.config.countType === 'words' && this.config.maxwords === undefined)
137+
) {
135138
if (!('Segmenter' in Intl)) {
136139
throw new SupportError(
137140
formatErrorMessage(
@@ -142,7 +145,7 @@ export class CharacterCount extends ConfigurableComponent {
142145
}
143146

144147
this.segmenter = new Intl.Segmenter(this.i18n.locale, {
145-
granularity: 'grapheme'
148+
granularity: this.config.countType === 'words' ? 'word' : 'grapheme'
146149
})
147150
}
148151

0 commit comments

Comments
 (0)