Skip to content

Commit cd58d35

Browse files
committed
feat(textarea): expose shadow parts
1 parent 27c18c2 commit cd58d35

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

core/api.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,6 +2515,14 @@ ion-textarea,css-prop,--placeholder-font-weight,md
25152515
ion-textarea,css-prop,--placeholder-opacity,ionic
25162516
ion-textarea,css-prop,--placeholder-opacity,ios
25172517
ion-textarea,css-prop,--placeholder-opacity,md
2518+
ion-textarea,part,bottom
2519+
ion-textarea,part,container
2520+
ion-textarea,part,counter
2521+
ion-textarea,part,error-text
2522+
ion-textarea,part,helper-text
2523+
ion-textarea,part,label
2524+
ion-textarea,part,native
2525+
ion-textarea,part,supporting-text
25182526

25192527
ion-thumbnail,shadow
25202528
ion-thumbnail,prop,mode,"ios" | "md",undefined,false,false

core/src/components/textarea/textarea.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ import type { TextareaChangeEventDetail, TextareaInputEventDetail } from './text
3636
* @slot label - The label text to associate with the textarea. Use the `labelPlacement` property to control where the label is placed relative to the textarea. Use this if you need to render a label with custom HTML. (EXPERIMENTAL)
3737
* @slot start - Content to display at the leading edge of the textarea. (EXPERIMENTAL)
3838
* @slot end - Content to display at the trailing edge of the textarea. (EXPERIMENTAL)
39+
*
40+
* @part container - The wrapper element for the textarea.
41+
* @part label - The label text describing the textarea.
42+
* @part native - The native textarea element.
43+
* @part supporting-text - Supporting text displayed beneath the textarea label.
44+
* @part helper-text - Supporting text displayed beneath the textarea label when the textarea is valid.
45+
* @part error-text - Supporting text displayed beneath the textarea label when the textarea is invalid and touched.
46+
* @part counter - The character counter displayed when the counter property is set.
47+
* @part bottom - The container element for helper text, error text, and counter.
3948
*/
4049
@Component({
4150
tag: 'ion-textarea',
@@ -633,6 +642,7 @@ export class Textarea implements ComponentInterface {
633642
'label-text-wrapper': true,
634643
'label-text-wrapper-hidden': !this.hasLabel,
635644
}}
645+
part="label"
636646
>
637647
{label === undefined ? <slot name="label"></slot> : <div class="label-text">{label}</div>}
638648
</div>
@@ -739,10 +749,10 @@ export class Textarea implements ComponentInterface {
739749
const { helperText, errorText, helperTextId, errorTextId, isInvalid } = this;
740750

741751
return [
742-
<div id={helperTextId} class="helper-text" aria-live="polite">
752+
<div id={helperTextId} class="helper-text" part="supporting-text helper-text" aria-live="polite">
743753
{!isInvalid ? helperText : null}
744754
</div>,
745-
<div id={errorTextId} class="error-text" role="alert">
755+
<div id={errorTextId} class="error-text" part="supporting-text error-text" role="alert">
746756
{isInvalid ? errorText : null}
747757
</div>,
748758
];
@@ -768,7 +778,11 @@ export class Textarea implements ComponentInterface {
768778
return;
769779
}
770780

771-
return <div class="counter">{getCounterText(value, maxlength, counterFormatter)}</div>;
781+
return (
782+
<div class="counter" part="counter">
783+
{getCounterText(value, maxlength, counterFormatter)}
784+
</div>
785+
);
772786
}
773787

774788
/**
@@ -790,7 +804,7 @@ export class Textarea implements ComponentInterface {
790804
}
791805

792806
return (
793-
<div class="textarea-bottom">
807+
<div class="textarea-bottom" part="bottom">
794808
{this.renderHintText()}
795809
{this.renderCounter()}
796810
</div>
@@ -875,9 +889,10 @@ export class Textarea implements ComponentInterface {
875889
<div class="start-slot-wrapper">
876890
<slot name="start"></slot>
877891
</div>
878-
<div class="native-wrapper" ref={(el) => (this.textareaWrapper = el)}>
892+
<div class="native-wrapper" ref={(el) => (this.textareaWrapper = el)} part="container">
879893
<textarea
880894
class="native-textarea"
895+
part="native"
881896
ref={(el) => (this.nativeInput = el)}
882897
id={inputId}
883898
disabled={disabled}

0 commit comments

Comments
 (0)