Web Components Mask Input Overview

    Ignite UI for Web Components Mask Input은 개발자가 구성 가능한 규칙에 따라 사용자 입력을 제어하고 표시되는 값의 형식을 지정할 수 있는 입력 필드입니다. 다양한 입력 옵션을 제공하고 사용 및 구성이 용이합니다.

    Web Components Mask Input Example

    Usage

    먼저 다음 명령을 실행하여 Ignite UI for Web Components 설치해야 합니다.

    npm install igniteui-webcomponents
    

    IgcMaskInputComponent 사용하기 전에 다음과 같이 등록해야 합니다.

    import { defineComponents, IgcMaskInputComponent } from 'igniteui-webcomponents';
    import 'igniteui-webcomponents/themes/light/bootstrap.css';
    
    defineComponents(IgcMaskInputComponent);
    

    Ignite UI for Web Components에 대한 전체 소개를 보려면 시작하기 항목을 읽어보세요.

    Mask Rules

    아래 표에는 지원되는 기본 제공 마스크 규칙이 나와 있습니다.

    마스크 캐릭터 설명
    0 숫자 [0-9]. 입력이 필요합니다.
    9 숫자 [0-9]. 입력은 선택사항입니다.
    # 숫자 [0-9], 더하기(+) 또는 빼기(-) 기호입니다. 입력이 필요합니다.
    편지 문자. 입력이 필요합니다.
    ? 편지 문자. 입력은 선택사항입니다.
    영숫자(문자 또는 숫자) 문자입니다. 입력이 필요합니다.
    영숫자(문자 또는 숫자) 문자입니다. 입력은 선택사항입니다.
    & 모든 키보드 문자. 입력이 필요합니다.
    모든 키보드 문자. 입력은 선택사항입니다.
    \ 마스크 플래그를 이스케이프하여 리터럴로 바꿉니다.

    이러한 플래그는 구성 요소 유효성 검사에도 참여합니다. 즉, 필수 위치 중 일부가 채워지지 않은 경우 입력이 유효하지 않게 됩니다(채워진 위치가 없거나 비어 있는 값은 여전히 required의 책임입니다). 이는 독립 실행형 입력과 양식에 포함된 경우 모두에 적용됩니다.

    Applying Mask

    Applying the mask is pretty straightforward. All you need to do is provide a predetermined pattern to the mask property of the input.

    아래 예에서는 내선 코드가 포함된 전화번호에 마스크를 적용하겠습니다.

    <igc-mask-input id="mask-input" mask="(####) 00-00-00 Ext. 9999">
        <igc-icon name="phone" slot="prefix"></igc-icon>
        <span slot="helper-text">Phone number</span>
    </igc-mask-input>
    

    그 후에는 브라우저에 다음이 표시되어야 합니다.

    Prompt Character

    Developers can customize the prompt symbol used for unfilled parts of the mask. To do this, simply provide any character to the prompt property:

    <igc-mask-input id="mask-input" mask="(####) 00-00-00 Ext. 9999" prompt="-"></igc-mask-input>
    

    기본적으로 prompt 문자는 밑줄 입니다.

    Placeholder

    Developers can also take advantage of the placeholder property, which serves the purpose of the native input placeholder attribute. If no value is provided for the placeholder, the value of the mask is used as such.

    <igc-mask-input id="mask-input" mask="00/00/0000" placeholder="dd/MM/yyyy"></igc-mask-input>
    

    Value Modes

    The IgcMaskInputComponent exposes a valueMode property that lets you choose between raw and withFormatting options to configure which input value (formatted or raw) to bind in your form when a specific mask is applied. By default, valueMode is set to raw. Try it for yourself in the example below:

    Styling

    구성 요소는 IgcMaskInputComponent 거의 모든 내부 요소에 대한 CSS 부분을 노출합니다. 다음 표에는 노출된 모든 CSS 부분이 나열되어 있습니다.

    이름 설명
    container 모든 기본 입력 요소를 보유하는 기본 래퍼입니다.
    input 기본 입력 요소입니다.
    label 기본 레이블 요소입니다.
    prefix 접두사 래퍼.
    suffix 접미사 래퍼.
    helper-text 도우미 텍스트 래퍼입니다.
    igc-mask-input::part(input) {
      background-color: var(--ig-primary-100);
      border-color: var(--ig-secondary-500);
      box-shadow: none;
    }
    
    igc-mask-input::part(input)::placeholder {
      color: var(--ig-primary-100-contrast);
    }
    

    Assumptions and limitations

    • 마스킹된 입력은 유형 속성은 항상 유형의 입력이므로 텍스트.
    • 실행 취소/다시 실행 동작은 현재 지원되지 않습니다.

    API References

    Additional Resources