탐색

v2.1.0
애플리케이션 블록

필터 바

목록의 범위를 좁히는 조건을 준비하고 적용한 뒤 칩으로 표시합니다.

필터 바는 조건으로 목록의 범위를 좁힙니다. 조건은 필드, 비교 방식, 값으로 구성되며, 예를 들어 “Status is Ready”나 “Duration is less than 60 seconds”와 같습니다. 조건은 팝오버에서 작성하고 한꺼번에 적용하며, 바에는 칩으로 표시되어 각 칩으로 조건을 하나씩 해제할 수 있습니다. 필터 바는 어떤 목록에서든 동작합니다. 여기서는 배포 목록의 범위를 좁히고, 테이블 뷰에서는 같은 바로 표의 범위를 좁힙니다.

필터 바

<section class="sheet container-inline flex flex-col overflow-hidden" data-example="filter-bar" aria-labelledby="fb-title">  <header class="flex flex-wrap items-center justify-between gap-sm p-md">    <div class="flex flex-col gap-3xs">      <h2 class="heading heading-sm" id="fb-title">Deployments</h2>      <p class="m(0) fg-text-muted" id="fb-summary" aria-live="polite">30 deployments in the last two weeks</p>    </div>  </header>  <div class="flex flex-wrap items-center gap-xs px-md pb-md">    <button type="button" class="btn btn-sm" popovertarget="fb-panel" data-filter="open">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M4.5365 3L11.4635 3A1 1 0 0 1 12.2548 4.6114L9.4587 8.2299A1 1 0 0 0 9.25 8.8413L9.25 11.323A1 1 0 0 1 8.6214 12.2514L7.875 12.55A0.8203 0.8203 0 0 1 6.75 11.7883L6.75 8.8413A1 1 0 0 0 6.5413 8.2299L3.7452 4.6114A1 1 0 0 1 4.5365 3Z" />      </svg>Filters      <span data-filter="count" aria-hidden="true" hidden>        <span class="badge badge-sm badge-ink badge-pill">0</span>      </span>    </button>    <div data-filter="applied" hidden>      <div class="flex flex-wrap items-center gap-xs">        <ul class="flex flex-wrap gap-xs m(0) p(0)" aria-label="Applied filters" data-filter="chips"></ul>        <button type="button" class="btn btn-quiet btn-sm" data-filter="clear-all">Clear all</button>      </div>    </div>  </div>  <div class="popover p(0) w(560)" id="fb-panel" popover role="dialog" aria-labelledby="fb-panel-title" style="--popover-max-width: min(36rem, calc(100vw - 2rem))" data-filter="panel">    <form class="flex flex-col" data-filter="form" novalidate>      <header class="flex flex-col gap-3xs px-md pt-md pb-sm">        <h3 class="heading heading-xs" id="fb-panel-title">Filter deployments</h3>        <p class="m(0) fg-text-muted">A deployment shows when it meets every condition.</p>      </header>      <ul class="flex flex-col gap-xs m(0) px-md py-xs" data-filter="conditions"></ul>      <p class="m(0) px-md py-xs fg-text-muted" data-filter="empty">No conditions yet: every deployment shows.</p>      <p class="m(0) px-md py-xs fg-danger" id="fb-error" role="alert" data-filter="error" hidden></p>      <div class="px-md pb-md">        <button type="button" class="btn btn-quiet btn-sm" data-filter="add">          <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">            <path d="M3 8L13 8" />            <path d="M8 3L8 13" />          </svg>Add condition</button>      </div>      <footer class="flex flex-wrap items-center justify-between gap-xs p-md bt(1) bt-solid b-line-hair">        <button type="button" class="btn btn-quiet btn-sm" data-filter="clear">Clear</button>        <div class="flex gap-xs">          <button type="button" class="btn btn-sm" data-filter="cancel">Cancel</button>          <button type="submit" class="btn btn-primary btn-sm">Apply</button>        </div>      </footer>    </form>  </div>  <ul class="list px-md bt(1) bt-solid b-line-hair" id="fb-results" aria-label="Matching deployments"></ul>  <p class="m(0) px-md pb-md pt-xs fg-text-muted" id="fb-more" hidden></p>  <template data-filter="row">    <li class="flex flex-wrap items-center gap-xs">      <span class="w(44) shrink(0) fg-text-muted text-end" data-part="joiner">Where</span>      <select class="select select-sm" aria-label="Field" data-part="field"></select>      <select class="select select-sm" aria-label="Comparison" data-part="operator"></select>      <input class="input input-sm grow(1) basis(128) min-w(0)" aria-label="Value" data-part="value" required>      <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Remove condition" data-part="remove">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <path d="M4 4L12 12" />          <path d="M4 12L12 4" />        </svg>      </button>    </li>  </template>  <template data-filter="choice">    <select class="select select-sm grow(1) basis(128)" aria-label="Value" data-part="value"></select>  </template>  <template data-filter="chip">    <li>      <span class="chip">        <span class="chip-label"></span>        <button type="button" class="chip-remove" aria-label="Remove the filter">          <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">            <path d="M4 4L12 12" />            <path d="M4 12L12 4" />          </svg>        </button>      </span>    </li>  </template>  <template id="fb-row">    <ul class="list">      <li class="list-row">        <div class="list-body">          <p class="list-title"></p>          <p class="list-description"></p>        </div>        <span class="list-end flex items-center gap-sm">          <span class="fg-text-muted"></span>          <span class="badge badge-dot"></span>        </span>      </li>    </ul>  </template>  <template id="fb-none">    <ul class="list">      <li class="list-row">        <div class="list-body">          <p class="list-title">No deployments match</p>          <p class="list-description">Remove a filter, or clear them all to see every deployment.</p>        </div>      </li>    </ul>  </template></section>
Filters를 열어 조건을 바꾸거나 추가한 뒤 Apply를 누르세요. 칩의 X 버튼을 누르면 해당 조건이 해제됩니다.

블록은 복사해 사용하는 마크업입니다. 페이지의 텍스트 색상과 크기를 따르며, 미리보기에서는 body에 fg-text-body text-sm 클래스를 설정합니다. 각 블록은 크기 컨테이너이므로 넓은 페이지, 사이드바 너비의 공간, 대화 상자 어디서든 자체 너비에 맞춰 배치가 바뀝니다.

#구성 요소

  • 버튼 하나로 조건을 엽니다. “Filters” 버튼에는 적용된 조건의 개수가 잉크 색 배지로 표시되므로, 바가 닫혀 있어도 목록의 범위가 좁혀져 있다는 것을 알 수 있습니다. 접근 가능한 이름에도 “Filters, 2 applied”처럼 이 정보를 포함합니다.
  • 조건은 초안입니다. 팝오버는 적용된 조건의 복사본을 엽니다. 조건을 추가하거나 필드나 값을 바꿔도 Apply를 누르기 전까지 목록은 바뀌지 않습니다. Cancel, Escape, 바깥 클릭은 초안을 버리고, Clear는 초안을 비우므로 그 상태에서 Apply를 누르면 모든 행이 표시됩니다.
  • 조건마다 한 행을 차지합니다. 첫 번째 조건 앞에는 “Where”, 나머지 앞에는 “and”가 붙습니다. 목록에 표시되는 항목은 모든 조건을 충족해야 합니다. 조건은 한 수준으로만 나열하며, 그룹이나 “or”는 지원하지 않습니다. 각 행은 필드를 고르는 셀렉트, 비교 방식을 고르는 셀렉트, 값, 그리고 조건을 삭제하는 눈에 띄지 않는 버튼으로 구성됩니다.
  • 필드가 나머지를 결정합니다. 텍스트는 포함, 일치, 불일치, 시작 문자열을 기준으로 비교하며 값을 텍스트로 입력합니다. 선택형 필드는 일치 또는 불일치로 비교하며 선택지 중 하나를 고릅니다. 숫자는 초과 또는 미만으로 비교하며 숫자 입력란에 값을 입력합니다. 날짜는 해당 날짜와 일치하는지, 그 전인지, 그 후인지 비교하며 날짜 입력란에 값을 입력합니다. 필드를 바꾸면 해당 조건 행을 초기화해 비교 방식에 맞지 않는 값이 남지 않도록 합니다.
  • 동작할 수 없는 조건은 적용되지 않습니다. 값이 없거나, 숫자에 문자가 들어 있거나, 날짜가 절반만 입력되면 값에 aria-invalid="true"가 지정되어 필드에 오류 상태를 나타내는 테두리가 표시되며, 조건 행 아래의 메시지가 어느 조건에 어떤 문제가 있는지 알려 줍니다. 포커스는 해당 값으로 이동하고 목록은 바뀌지 않습니다.
  • 적용된 조건은 칩입니다. 각 칩은 조건을 텍스트로 전달하고, “Remove the filter Status is Ready”처럼 조건에 맞는 이름이 지정된 삭제 버튼이 있습니다. 행 끝의 Clear all은 모든 조건을 한 번에 해제합니다.
  • 목록은 무엇을 표시하는지 알려 줍니다. 제목 아래의 요약은 “12 of 30 deployments match all 2 filters”처럼 전체 중 일치하는 항목 수를 세고, 일치하는 항목이 없으면 목록이 그 사실과 돌아가는 방법을 알려 줍니다.

#스크립트가 필요한 동작

예제는 세 개의 모듈로 구성됩니다. query.js는 조건을 다룹니다. 각 유형이 제공하는 비교 방식, 조건의 문제점, 행이 조건을 충족하는지 여부, 검색, 정렬, 페이지 나누기를 처리하며, 일반 행을 읽고 요소에는 접근하지 않습니다. filters.js는 바를 동작시킵니다. 마크업에 들어 있는 조건 행, 선택지, 칩 템플릿을 복사해 채우고, 적용된 조건으로 onChange를 호출합니다. main.js는 그 조건으로 목록을 그립니다. 애플리케이션은 자체 데이터 소스에 같은 질의를 보내면 되며, 바는 바뀌지 않습니다. 적용된 조건을 filter() 대신 서버로 보내세요.

스크립트가 없으면 바에서 조건을 준비할 수 없습니다. 대신 목록에 필드마다 셀렉트가 있는 <form method="get">을 두면 서버가 쿼리 문자열을 받아 처리합니다.

#접근성

  • 팝오버는 제목 “Filter deployments”로 이름을 지정한 role="dialog"입니다. 팝오버를 열면 첫 번째 조건의 필드로, 조건이 없으면 Add condition으로 포커스가 이동하며, 닫으면 Filters로 포커스가 돌아갑니다.
  • 행의 각 컨트롤 이름에는 “Field of condition 2”, “Value of condition 2”, “Remove condition 2”처럼 조건 번호가 포함됩니다. 숫자 값은 단위를 함께 알려 줍니다.
  • 적용할 수 없는 조건에 대한 메시지는 role="alert"이며 aria-describedby로 해당 값과 연결되므로, 나타날 때 읽히고 값에서도 다시 읽힙니다.
  • 칩을 삭제하면 포커스가 다음 칩으로, 마지막 칩이었다면 Filters로 이동하며, Clear all은 포커스를 Filters로 옮깁니다. 요약은 polite 라이브 영역이므로 필터가 바뀌면 보조 기술이 새 결과 수를 읽어 줍니다.
  • 조건은 칩 안의 텍스트로 전달하며 색상으로 전달하지 않습니다. 상태는 목록에서 이름 옆에 배지 톤을 유지합니다.