From 264d69c933370b3321dfcd83d823222e730e3fe0 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 16 Aug 2020 16:39:57 +0900 Subject: Improve a11y in completion items --- src/console/components/console/Completion.tsx | 48 ++++++++++++++++------ src/console/components/console/CompletionItem.tsx | 18 +++++--- src/console/components/console/CompletionTitle.tsx | 10 +++-- 3 files changed, 54 insertions(+), 22 deletions(-) (limited to 'src/console/components') diff --git a/src/console/components/console/Completion.tsx b/src/console/components/console/Completion.tsx index aefee32..56c5de3 100644 --- a/src/console/components/console/Completion.tsx +++ b/src/console/components/console/Completion.tsx @@ -63,29 +63,51 @@ class Completion extends React.Component { } render() { - let eles = []; - let index = 0; + let itemIndex = 0; + let viewIndex = 0; + const groups: Array = []; + const viewOffset = this.state.viewOffset; + const viewSize = this.props.size; - for (const group of this.props.completions) { - eles.push(); + this.props.completions.forEach((group, groupIndex) => { + const items = []; + const title = ( + + ); + ++viewIndex; for (const item of group.items) { - eles.push( + items.push( ); - ++index; + ++viewIndex; + ++itemIndex; } - } - - const viewOffset = this.state.viewOffset; - eles = eles.slice(viewOffset, viewOffset + this.props.size); + groups.push( +
+ {title} +
    {items}
+
+ ); + }); - return
    {eles}
; + return
{groups}
; } } diff --git a/src/console/components/console/CompletionItem.tsx b/src/console/components/console/CompletionItem.tsx index da07bf0..76db5b5 100644 --- a/src/console/components/console/CompletionItem.tsx +++ b/src/console/components/console/CompletionItem.tsx @@ -1,7 +1,11 @@ import React from "react"; import styled from "../Theme"; -const Container = styled.li<{ icon: string; highlight: boolean }>` +const Container = styled.li<{ + shown: boolean; + icon: string; + highlight: boolean; +}>` backgroundimage: ${({ icon }) => "url(" + icon + ")"}; background-color: ${({ highlight, theme }) => highlight @@ -11,6 +15,7 @@ const Container = styled.li<{ icon: string; highlight: boolean }>` highlight ? theme.completionSelectedForeground : theme.completionItemForeground}; + display: ${({ shown }) => (shown ? "display" : "none")}; padding-left: 1.5rem; background-position: 0 center; background-size: contain; @@ -34,16 +39,19 @@ const Description = styled.span` `; interface Props { + shown: boolean; highlight: boolean; caption?: string; url?: string; icon?: string; } -const CompletionItem: React.FC = ({ highlight, caption, url, icon }) => ( - - {caption} - {url} +const CompletionItem: React.FC & Props> = ( + props +) => ( + + {props.caption} + {props.url} ); diff --git a/src/console/components/console/CompletionTitle.tsx b/src/console/components/console/CompletionTitle.tsx index 55c3c2e..ec2fc8b 100644 --- a/src/console/components/console/CompletionTitle.tsx +++ b/src/console/components/console/CompletionTitle.tsx @@ -1,7 +1,8 @@ import React from "react"; import styled from "../Theme"; -const Li = styled.li` +const Li = styled.li<{ shown: boolean }>` + display: ${({ shown }) => (shown ? "display" : "none")}; background-color: ${({ theme }) => theme.completionTitleBackground}; color: ${({ theme }) => theme.completionTitleForeground}; font-weight: bold; @@ -10,11 +11,12 @@ const Li = styled.li` `; interface Props { + shown: boolean; title: string; } -const CompletionTitle: React.FC = ({ title }) => { - return
  • {title}
  • ; -}; +const CompletionTitle: React.FC & Props> = ( + props +) =>
  • {props.title}
  • ; export default CompletionTitle; -- cgit v1.2.3