Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix blocks Alert, Card Semplice, Card immagine, Accordion keyboa… #348

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

- Nel template Blocco link solo immagini con link esterni, icona accessibilità per link esterni ora è disattivabile attraverso opzione del template
- Migliorata l'accessibilità e il supporto Screen Reader per il menu a tendina "Ordina Per" nella pagina di ricerca
- Migliorata la navigazione da tastiera quando si è in modifica dei blocchi Alert, Card Semplice, Card con Immagine, Accordion

### Fix

Expand Down
46 changes: 26 additions & 20 deletions src/components/ItaliaTheme/Blocks/Accordion/Block/EditBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ class EditBlock extends SubblockEdit {
this.accordion_item_ref = React.createRef();
}

componentDidMount() {
// eslint-disable-next-line no-unused-expressions
this.accordion_item_ref?.current?.addEventListener('keydown', (e) => {
if (e.keyCode === 13) {
if (!(this.state.focusOn === 'text')) {
this.setState({ focusOn: 'text' });
}
}
});
}
/**
* Render method.
* @method render
Expand Down Expand Up @@ -105,12 +95,20 @@ class EditBlock extends SubblockEdit {
placeholder={this.props.intl.formatMessage(
messages.titlePlaceholder,
)}
nextFocus="text"
prevFocus="text"
disableMoveToNearest={true}
setFocus={(f) => {
this.setState({ focusOn: f });
onSelectBlock={() => {}}
onAddBlock={() => {
this.setState({ focusOn: 'text' });
}}
onFocusNextBlock={() => {
this.setState({ focusOn: 'text' });
}}
onFocusPreviousBlock={
this.props.isFirst
? this.props.onFocusPreviousBlock
: () => {
this.props.onSubblockChangeFocus(this.props.index - 1);
}
}
showToolbar={false}
key="title"
/>
Expand All @@ -135,11 +133,19 @@ class EditBlock extends SubblockEdit {
placeholder={this.props.intl.formatMessage(
messages.textPlaceholder,
)}
disableMoveToNearest={true}
prevFocus="title"
nextFocus="title"
setFocus={(f) => {
this.setState({ focusOn: f });
onAddBlock={this.props.onFocusNextBlock}
onFocusNextBlock={
this.props.isLast
? this.props.onFocusNextBlock
: () => {
this.setState({ focusOn: null });
this.props.onSubblockChangeFocus(
this.props.index + 1,
);
}
}
onFocusPreviousBlock={() => {
this.setState({ focusOn: 'title' });
}}
key="text"
/>
Expand Down
10 changes: 9 additions & 1 deletion src/components/ItaliaTheme/Blocks/Accordion/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,17 @@ class Edit extends SubblocksEdit {
<EditBlock
data={subblock}
index={subindex}
selected={this.isSubblockSelected(subindex)}
selected={
this.props.selected &&
this.isSubblockSelected(subindex)
}
{...this.subblockProps}
openObjectBrowser={this.props.openObjectBrowser}
onFocusPreviousBlock={this.props.onFocusPreviousBlock}
onFocusNextBlock={this.props.onFocusNextBlock}
onSubblockChangeFocus={this.onSubblockChangeFocus}
isLast={this.state.subblocks.length - 1 === subindex}
isFirst={subindex === 0}
/>
</div>
))}
Expand Down
37 changes: 25 additions & 12 deletions src/components/ItaliaTheme/Blocks/Alert/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,25 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { compose } from 'redux';
import { injectIntl } from 'react-intl';

import cx from 'classnames';
import { Container, Row, Col } from 'design-react-kit';

import { createContent } from '@plone/volto/actions';
import { SidebarPortal } from '@plone/volto/components';
import { EditTextBlock } from '@plone/volto/components';
import { defineMessages, injectIntl } from 'react-intl';

import {
AlertSidebar,
TextEditorWidget,
} from 'design-comuni-plone-theme/components/ItaliaTheme';

import { AlertSidebar } from 'design-comuni-plone-theme/components/ItaliaTheme';
const messages = defineMessages({
content_placeholder: {
id: 'Type text…',
defaultMessage: 'Digita il testo…',
},
});
/**
* Edit Alert block class.
* @class Edit
Expand Down Expand Up @@ -84,20 +94,23 @@ class Edit extends Component {
</Col>
)}
<Col>
<EditTextBlock
<TextEditorWidget
data={this.props.data}
detached={true}
index={this.props.index}
fieldName="text"
selected={this.props.selected}
block={this.props.block}
onChangeBlock={(data) =>
this.props.onChangeBlock(this.props.block, data)
}
placeholder={this.props.intl.formatMessage(
messages.content_placeholder,
)}
showToolbar={true}
onSelectBlock={this.props.onSelectBlock}
onAddBlock={this.props.onAddBlock}
onChangeBlock={this.props.onChangeBlock}
onDeleteBlock={this.props.onDeleteBlock}
onMutateBlock={this.props.onMutateBlock}
onFocusPreviousBlock={this.props.onFocusPreviousBlock}
index={this.props.index}
onFocusNextBlock={this.props.onFocusNextBlock}
onSelectBlock={this.props.onSelectBlock}
blockNode={this.blockNode}
onFocusPreviousBlock={this.props.onFocusPreviousBlock}
/>
</Col>
</Row>
Expand Down
38 changes: 28 additions & 10 deletions src/components/ItaliaTheme/Blocks/CTABlock/Block.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Container } from 'design-react-kit';
/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/click-events-have-key-events */
import React, { useRef, useState } from 'react';
import React, { useRef, useState, useEffect } from 'react';
import { defineMessages, useIntl } from 'react-intl';

import Image from '@plone/volto/components/theme/Image/Image';
Expand Down Expand Up @@ -35,16 +35,26 @@ const Block = ({
onSelectBlock,
onAddBlock,
index,
onFocusNextBlock,
onFocusPreviousBlock,
selected,
}) => {
const intl = useIntl();
const title = data?.cta_title?.blocks[0]?.text;
const hasImage = data?.showImage && data?.ctaImage?.length > 0;
const content = data?.cta_content;
const showFullwidth = data?.showFullWidth;

const [selected, setSelected] = useState('title');
const [selectedField, setSelectedField] = useState('title');
const titleRef = useRef();
const contentRef = useRef();
useEffect(() => {
if (selected) {
setSelectedField('title');
} else {
setSelectedField(null);
}
}, [selected]);

return (
<div
Expand All @@ -62,7 +72,7 @@ const Block = ({
}

if (titleRef.current.contains(e.target)) {
setSelected('content');
setSelectedField('content');
}
}
}}
Expand Down Expand Up @@ -90,24 +100,28 @@ const Block = ({
<div
ref={titleRef}
onClick={() => {
setSelected('title');
setSelectedField('title');
}}
onFocus={() => {
setSelected('title');
setSelectedField('title');
}}
>
<TextEditorWidget
data={data}
fieldName="cta_title"
selected={selected === 'title'}
selected={selectedField === 'title'}
block={block}
onChangeBlock={(data) => onChangeBlock(block, data)}
placeholder={intl.formatMessage(messages.cta_title)}
showToolbar={false}
onSelectBlock={() => {}}
onAddBlock={() => {
setSelected('content');
setSelectedField('content');
}}
onFocusNextBlock={() => {
setSelectedField('content');
}}
onFocusPreviousBlock={onFocusPreviousBlock}
/>
</div>
) : (
Expand All @@ -118,23 +132,27 @@ const Block = ({
<div
ref={contentRef}
onClick={() => {
setSelected('content');
setSelectedField('content');
}}
onFocus={() => {
setSelected('content');
setSelectedField('content');
}}
>
<TextEditorWidget
data={data}
fieldName="cta_content"
selected={selected === 'content'}
selected={selectedField === 'content'}
block={block}
onChangeBlock={(data) => onChangeBlock(block, data)}
placeholder={intl.formatMessage(messages.cta_content)}
showToolbar={true}
onSelectBlock={onSelectBlock}
onAddBlock={onAddBlock}
index={index}
onFocusNextBlock={onFocusNextBlock}
onFocusPreviousBlock={() => {
setSelectedField('title');
}}
/>
</div>
) : (
Expand Down
Loading