Skip to content

Commit 9e7ca65

Browse files
jennurkpsherva
authored andcommitted
elements: add a11y friendly popup component
1 parent 7b9391c commit 9e7ca65

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// This file is part of React-Invenio-Forms
2+
// Copyright (C) 2023 CERN.
3+
//
4+
// React-Invenio-Forms is free software; you can redistribute it and/or modify it
5+
// under the terms of the MIT License; see LICENSE file for more details.
6+
7+
import React, { Component } from "react";
8+
import PropTypes from "prop-types";
9+
import { Popup } from "semantic-ui-react";
10+
11+
export class InvenioPopup extends Component {
12+
render() {
13+
const { popupId, size, trigger, content, position, inverted, ariaLabel } =
14+
this.props;
15+
16+
return (
17+
<Popup
18+
id={popupId}
19+
size={size}
20+
position={position}
21+
inverted={inverted}
22+
on={["hover", "focus"]}
23+
trigger={React.cloneElement(trigger, {
24+
"role": "button",
25+
"tabIndex": 0,
26+
"aria-label": ariaLabel,
27+
})}
28+
content={
29+
<p role="tooltip" aria-live="polite">
30+
{content}
31+
</p>
32+
}
33+
/>
34+
);
35+
}
36+
}
37+
38+
InvenioPopup.propTypes = {
39+
ariaLabel: PropTypes.string.isRequired,
40+
trigger: PropTypes.object.isRequired,
41+
content: PropTypes.string.isRequired,
42+
popupId: PropTypes.string.isRequired,
43+
inverted: PropTypes.bool,
44+
position: PropTypes.string,
45+
size: PropTypes.string,
46+
};
47+
48+
InvenioPopup.defaultProps = {
49+
inverted: false,
50+
position: "top left",
51+
size: "small",
52+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file is part of React-Invenio-Forms
2+
// Copyright (C) 2022 CERN.
3+
//
4+
// React-Invenio-Forms is free software; you can redistribute it and/or modify it
5+
// under the terms of the MIT License; see LICENSE file for more details.
6+
7+
/**
8+
* This folder contains accessibility friendly components.
9+
*/
10+
export { InvenioPopup } from "./InvenioPopup";

src/lib/elements/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/**
88
* This folder contains general purpose reusable components.
99
*/
10+
export * from "./accessibility";
1011
export { Image } from "./Image";
1112
export { GridResponsiveSidebarColumn } from "./GridResponsiveSidebarColumn";
1213
export { ErrorMessage } from "./ErrorMessage";

0 commit comments

Comments
 (0)