본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Live region 컴포넌트

원문 보기 위키 갱신

Live region은 보조 기술(assistive technology)에 페이지 변경을 공지하는 데 사용되는 비시각적 컴포넌트입니다. 이 컴포넌트는 message 속성 또는 children 슬롯의 텍스트 콘텐츠에서 가져온 상태 메시지를 포함하며, 컴포넌트가 처음 렌더링될 때와 메시지 콘텐츠가 변경될 때 스크린 리더에 공지합니다. 포커스 이동이 불가능하거나 사용자에게 지나치게 방해가 될 때 컨텍스트 밖의 변경을 알리는 데 주로 사용합니다.

출처: 문서

본문

Live region은 보조 기술에 페이지 변경을 공지하는 데 사용되는 비시각적 컴포넌트입니다.

개발 지침 (Development guidelines)

Live region은 스크린 리더 및 기타 보조 기술 사용자가 현재 포커스된 페이지 요소 밖에서 발생하는 동적 변경 사항을 알 수 있도록 하는 접근성 조치입니다. live region 컴포넌트는 message 속성으로 제공되거나 children 슬롯의 텍스트 콘텐츠에서 추출된 상태 메시지를 포함합니다. 이 메시지는 컴포넌트가 처음 렌더링될 때와 메시지 콘텐츠가 변경될 때 스크린 리더에 공지됩니다. 공지 메시지는 페이지의 특정 컴포넌트나 섹션과 연결되지 않습니다. 단락 텍스트나 다른 페이지 요소와 달리, live region 콘텐츠는 스크린 리더가 내비게이션하거나 반복할 수 없으므로 공지 메시지는 명확하고 간결해야 합니다.

사용자의 즉각적인 컨텍스트 밖에서 발생하는 변경을, 포커스 이동이 불가능하거나 사용자에게 지나치게 방해가 될 때(예: 비동기 페이지 업데이트 또는 정보 상태 메시지) 스크린 리더 사용자에게 알리는 데 live region을 사용하세요. 페이지 변경이 사용자 동작 직후에 이어지고 업데이트된 요소에 포커스 가능한 컨트롤이 포함되어 있다면, live region을 사용하는 대신 포커스를 그 컨트롤로 이동하는 것이 더 선호될 수 있습니다. 포커스 관리에 대한 더 많은 지침은 focus management principles를 참조하세요.

Assertive 공지는 진행 중인 스크린 리더 공지를 중단하며 사용자에게 방해가 될 수 있습니다. 이는 중단이 필요한 시급하거나 즉각적인 공지에만 사용해야 합니다. 예를 들어 form field는 포커스가 활성 입력을 떠날 때 다음 폼 필드 컨트롤의 공지를 중단하기 위해 오류 및 경고 텍스트에 assertive live region을 사용합니다.

ARIA live region 패턴에 대한 자세한 내용은 MDN에서 확인할 수 있습니다.

테스트 유틸리티 클래스가 처음이라면 소개 글에서 더 자세히 배울 수 있습니다.

단위 테스트 예시 (Unit testing examples)

live region 선택하기

import { render } from '@testing-library/react';
import createWrapper from '@cloudscape-design/components/test-utils/dom';

import LiveRegion from '@cloudscape-design/components/live-region';

describe('<LiveRegion />', () => {
  it('renders the live-region component', () => {
    const { container } = render(<LiveRegion />);
    const wrapper = createWrapper(container);

    expect(wrapper.findLiveRegion()).toBeTruthy();
  });

  it('selects all live-region components', () => {
    const { container } = render(<>
      <LiveRegion />
      <LiveRegion />
      <LiveRegion />
    </>);
    const wrapper = createWrapper(container);

    const components = wrapper.findAllLiveRegions();
    expect(components).toHaveLength(3)
  });
});

live region 콘텐츠 선택하기

import LiveRegion from '@cloudscape-design/components/live-region';
import createWrapper from '@cloudscape-design/components/test-utils/dom';

import { render } from '@testing-library/react';
import React from 'react';

function Component() {
  return <LiveRegion>Status update: 5 items loaded</LiveRegion>;
}

describe('<LiveRegion />', () => {
  it('selects the live region content', () => {
    const { container } = render(<Component />);
    const wrapper = createWrapper(container);

    const liveRegion = wrapper.findLiveRegion()!;

    expect(liveRegion).toBeTruthy();
    expect(liveRegion.getElement().textContent).toContain('5 items loaded');
  });
});

숨겨진 live region

import LiveRegion from '@cloudscape-design/components/live-region';
import createWrapper from '@cloudscape-design/components/test-utils/dom';

import { render } from '@testing-library/react';
import React from 'react';

function Component() {
  return <LiveRegion hidden={true}>Hidden announcement</LiveRegion>;
}

describe('<LiveRegion />', () => {
  it('renders a hidden live region', () => {
    const { container } = render(<Component />);
    const wrapper = createWrapper(container);

    const liveRegion = wrapper.findLiveRegion()!;

    expect(liveRegion).toBeTruthy();
    expect(liveRegion.getElement().textContent).toContain('Hidden announcement');
  });
});

단위 테스트 API (Unit testing APIs)

LiveRegionWrapper

Name Return type Description Parameters
사용 가능한 메서드 없음이 래퍼는 추가 메서드를 제공하지 않습니다.

통합 테스트 예시 (Integration testing examples)

live region 콘텐츠 선택하기

import createWrapper from '@cloudscape-design/components/test-utils/selectors';

/**
 * browser - is a global object representing your testing framework.
 * The exact API could be different for your stack.
 */

describe('LiveRegion', () => {
  it('selects the live region content', async () => {
    await browser.url('your-test-page');
    const wrapper = createWrapper();

    const liveRegionSelector = wrapper.findLiveRegion().toSelector();
    const isExisting = await browser.$(liveRegionSelector).isExisting();

    expect(isExisting).toBe(true);

    const text = await browser.$(liveRegionSelector).getText();

    expect(text).toBeTruthy();
  });
});

통합 테스트 API (Integration testing APIs)

LiveRegionWrapper

Name Return type Description Parameters
사용 가능한 메서드 없음이 래퍼는 추가 메서드를 제공하지 않습니다.

일반 지침 (General guidelines)

권장 사항 (Do)

  • live 공지를 위해 명확하고 간결한 메시지를 제공하세요(1-2문장).
  • Cloudscape 컴포넌트와 함께 live region을 언제 사용할지 관련 컴포넌트의 개발 및 접근성 지침을 확인하세요.

금지 사항 (Don't)

  • live region 컴포넌트 안에 링크나 버튼을 포함한 인터랙티브 요소를 배치하지 마세요. 대신 포커스를 인터랙티브 요소로 이동하세요.

작성 지침 (Writing guidelines)

일반 작성 지침 (General writing guidelines)

  • 문장형 대소문자(sentence case)를 사용하되, 문맥에 따라 고유 명사와 브랜드 이름은 올바르게 대문자로 표기하세요.

  • 헤더와 버튼을 제외하고는 끝 구두점을 사용하세요. 느낌표는 사용하지 마세요.

  • 현재 시제 동사와 능동태를 사용하세요.

  • 글에서 please, thank you, 줄임표( ... ), 앰퍼샌드( & ), e.g., i.e., etc. 를 사용하지 마세요.

  • 방향을 나타내는 언어는 피하세요.

    • 예: 위(above) 대신 이전(previous), 아래(below) 대신 다음(following) 을 사용하세요.
  • 기기에 독립적인 언어를 사용하세요.

    • 예: 클릭(click) 대신 선택(choose) 또는 select를 사용하세요.

컴포넌트별 지침 (Component-specific guidelines)

  • 명확하고 간결한 문장을 사용하세요(1-2문장).

접근성 지침 (Accessibility guidelines)

  • live region 컴포넌트 안에 링크나 버튼을 포함한 인터랙티브 요소를 배치하지 마세요. live 공지는 페이지 컨텍스트 없이 이루어지므로, 스크린 리더 사용자는 live region 안에 배치된 인터랙티브 요소를 찾는 방법을 알 수 없습니다.
  • children 슬롯을 사용할 때는 텍스트 또는 비의미적 요소(예: div 또는 span)만 배치하세요. aria-label, aria-labelledby 또는 alt로 레이블된 요소는 공지 메시지에 포함되지 않습니다.

더 알아보기 (Learn more)