File tree Expand file tree Collapse file tree
packages/govuk-frontend/src/govuk/components/character-count Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ export class CharacterCount extends ConfigurableComponent {
3131 /** @private */
3232 countFunction
3333
34+ /** @private */
35+ countFunctionContext
36+
3437 /**
3538 * @private
3639 * @type {Intl.Segmenter | null }
@@ -160,6 +163,12 @@ export class CharacterCount extends ConfigurableComponent {
160163 this . config . countFunction ??
161164 this . countFunctions [ this . config . countType ?? 'length' ]
162165
166+ // Cache the count function context
167+ this . countFunctionContext = {
168+ config : this . config ,
169+ segmenter : this . segmenter
170+ }
171+
163172 // Determine the limit attribute (characters or words)
164173 this . maxLength = this . config . maxlength ?? Infinity
165174
@@ -392,12 +401,10 @@ export class CharacterCount extends ConfigurableComponent {
392401 * @private
393402 */
394403 updateCount ( ) {
395- const text = this . $textarea . value
396-
397- this . count = this . countFunction ( text , {
398- config : this . config ,
399- segmenter : this . segmenter
400- } )
404+ this . count = this . countFunction (
405+ this . $textarea . value ,
406+ this . countFunctionContext
407+ )
401408 }
402409
403410 /**
You can’t perform that action at this time.
0 commit comments